tags:

views:

38

answers:

2

What does dt.rows.count==0 actually mean? can anybody help me... i want the explanation for the following code.. I used this code for saving & updating a row

protected void Button1_Click(object sender, EventArgs e) { //create the database connection

    //create the command object and store the sql query
    DataTable dt = new DataTable();
    OleDbDataAdapter adapter = new OleDbDataAdapter("select Firstname from student where Firstname = '" + TextBox2.Text  + "'", aConnection);
    adapter.Fill(dt);
    aConnection.Open();
    if (dt.Rows.Count == 0)
    {
        OleDbCommand aCommand = new OleDbCommand("insert into Student(Firstname,Lastname,Address) values('" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')", aConnection);
        aCommand.ExecuteNonQuery();
    }
    else
    {
        OleDbCommand aComman= new OleDbCommand("Update Student set Firstname='" + TextBox2.Text + "',Lastname='" + TextBox3.Text + "',Address='" + TextBox4.Text + "' where Firstname='" + TextBox2.Text + "'", aConnection);
        aComman.ExecuteNonQuery();
    }

    //close the connection Its important.
    aConnection.Close();
    sss();

}
A: 

There is no rows in your Datatable. (it's datatable isn't it?)

Arseny
A: 

if dt is your DataTable

there is no row in dt :)

Azhar