Database table to Datatable in C#???????? [Resolved]

Posted by Sabarimahesh under C# on 4/12/2012 | Points: 10 | Views : 1501 | Status : [Member] | Replies : 8
private void LoadDataToTable()
{
DataTable Tb1= null;
using (SqlConnection connection =new SqlConnection("con"))
{
using (SqlCommand cmd=connection.CreateCommand())
{
cmd.CommandText = "select * from Student";
cmd.CommandType = System.Data.CommandType.Text;
using (SqlDataReader read=cmd.ExecuteReader())
{
if (reader.HasRows)
{
Tb1= new DataTable();
Tb1.FIll(read);
}
}
}
}
}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M



Responses

Posted by: Leila on: 4/12/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
private void LoadDataToTable()

{
DataTable Tb1= null;
using (SqlConnection connection =new SqlConnection("con"))
{
using (SqlCommand cmd=connection.CreateCommand())
{
cmd.CommandText = "select * from Student";
cmd.CommandType = System.Data.CommandType.Text;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
Tb1 = ds.Tables[0];
}
}
}


Thanks,
Leila

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

Posted by: Leila on: 4/12/2012 [Member] Starter | Points: 25

Up
0
Down
Can you please precise what the question?
Did the code you wrote give error?

Thanks,
Leila

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

Posted by: Sabarimahesh on: 4/12/2012 [Member] Bronze | Points: 25

Up
0
Down
Database table to datatable

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

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

Posted by: Rajni.Shekhar on: 4/12/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,
Did you have any Load method to fill your datatable?

Leila code is correct to fill data table.

Thanks,
Rajni Shekhar

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

Posted by: Sabarimahesh on: 4/12/2012 [Member] Bronze | Points: 25

Up
0
Down
Sorry i changed it

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

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

Posted by: Sakthi.Singaravel on: 4/12/2012 [Member] Silver | Points: 25

Up
0
Down
thank you Leila..
ur answer used for me..

Regards,
Singaravel M

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

Posted by: Leila on: 4/12/2012 [Member] Starter | Points: 25

Up
0
Down
If so, can u plz mark it as an answer:)

Thanks,
Leila

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

Posted by: Sabarimahesh on: 4/12/2012 [Member] Bronze | Points: 25

Up
0
Down
Leila

Thank You

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

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

Login to post response