Monday, July 7, 2014

Simple DataReader Example with Code

Hello Friends, Now a days we mostly handles queries inline.
Here's a simple code to fetch data using DataReader and showing it into Combobox.

SqlCommand cmd = new SqlCommand("select MainCategoryId from    tblMainCategoryMaster where Enable=1", global.cn);
global.cn.Open();
SqlDataReader dr1 = cmd.ExecuteReader();
cmbMainCategoryId.Items.Add("--Select--");
while (dr1.Read())
{
     cmbMainCategoryId.Items.Add(dr1["MainCategoryId"].ToString());
}

global.cn.Close();


Hope it will save your time in future.
PS : It is mostly helpful in interviews :)

Enjoy the day with Lots of smile and Happiness.....

No comments:

Post a Comment