dataset fill method in c# code

Posted by Sekar.C under C# on 3/14/2012 | Points: 10 | Views : 11010 | Status : [Member] | Replies : 4
hi,

What the use of using table name (buyer) in data set fill method please explain
SqlCommand cc1 = new SqlCommand("delete feedback where Name='" + GridView1.Rows[e.RowIndex].Cells[1].Text + "'", con);
cc1.ExecuteNonQuery();
SqlCommand cmd1 = new SqlCommand("select * from feedback", con);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "buyer");
GridView1.DataSource = ds1.Tables[0];
GridView1.DataBind();
con.Close();

regard
sekar.c

Regards
Sekar.c



Responses

Posted by: Sksamantaray on: 3/14/2012 [Member] Silver | Points: 25

Up
0
Down
When a dataset has multiple tables instead of using index you can use the table name, which is easy to remember and handle.



Thanks,
Sanjay

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 3/14/2012 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Here in fact you do not need to write the 2nd parameter as table name in the Fill method of the DataAdapter. In fact fill method of the DataAdapter also accepts table object instead of DataSet. So in case your sql statement or stored procedure is returning only one result set, do not use DataSet into the fill method, simply use DataTable object.

Now coming to the 2nd parameter in the fill method (in your case 'buyer') is simply a name through which you can call that result set (in this case table). So either you write dSet.Tables[0] or dSet.Tables["buyer"] should give you the same result set.

Hope this helps.

Thanks



Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 3/14/2012 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Good job @Sksamantaray, you answered before I hit the submit button. One line and simple answer, keep it up!

:)

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/14/2012 [Member] Silver | Points: 25

Up
0
Down
Thanks Sheonarayan,
Its really grate to here from you that to with good comments.
Your descriptive explanation is also very much easy to understand.

Thanks,
Sanjay

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response