50. how to retrieve particular column data in the data set or data table [Resolved]

Posted by Murugavelmsc under ASP.NET on 2/27/2013 | Points: 10 | Views : 2544 | Status : [Member] | Replies : 2
how to retrieve particular column data in the data set or data table

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/



Responses

Posted by: Ankitsrist on: 2/27/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
hello Murugavelmsc,
have a look on my code may be it will help you
  SqlCommand cmd = new SqlCommand("select * from leavereminder", db.sqlcon);

SqlDataAdapter adp = new SqlDataAdapter(cmd);
//create object for datable
DataTable dt = new DataTable();
//fill it
adp.Fill(dt);
//check for more then 0 rows
if (dt.Rows.Count > 0)
{
//status is my column name, here i have checked for the "pending" value
if (dt.Rows[0]["status"].ToString() == "pending")
{
//sending mechanism if satisfied condition
sendmail(dt.Rows[0]["email"].ToString(), dt.Rows[0]["name"].ToString());
}

}

here i have used datatable bcoz i have to deal with single table, and dataset contains collections of tables so it become heavy so avoid to use dataset...

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

Posted by: Santhi on: 2/27/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

write the select query what you need to select from the table.
Fill the dataset by that column values.
Example:
Sqlconnection con = new sqlconnection(connectionstring);

string Query = "select columnname from tablename";
con .Open();
SqlDataAdapter a = new SqlDataAdapter(Query,con);
DataTable t = new DataTable();
a.Fill(t);


Thanks & Regards,
Santhi .V

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

Login to post response