An example of sqldatareader is something like this :
SqlConnection obj_con;
SqlCommand obj_com;
try
{
obj_con = new SqlConnection("your connection string");
obj_com = new SqlCommand();
obj_com.Connection = obj_con;
obj_com.CommandText = ("Select * from Student where StudId=@sid and Password=@pw";)
SqlParameter p_Id = new SqlParameter("@sid", SqlDbType.NVarChar);
p_Id.Direction = ParameterDirection.Input;
p_Id.Value = sid;
obj_com.Parameters.Add(p_Id);
SqlParameter p_pass = new SqlParameter("@pw", SqlDbType.NVarChar);
p_pass.Direction = ParameterDirection.Input;
p_pass.Value = pw;
obj_com.Parameters.Add(p_pass);
obj_con.Open();
SqlDataReader obj_rd = obj_com.ExecuteReader();
while (obj_rd.Read())
{
StudFirstName = obj_rd[0].ToString();
StudLastName = obj_rd[1].ToString();
StudId = obj_rd[2].ToString();
Gender = obj_rd[3].ToString();
Address = obj_rd[4].ToString();
EmailId = obj_rd[5].ToString();
BranchId = obj_rd[6].ToString();
SemesterId = obj_rd[7].ToString();
}
obj_con.Close();
}
catch (Exception s)
{
}
if you have more that one result you can create a list of url list url and add each result to your list.obj_rd[0] refers to a first columns in my result.So you have more that one column so you can get the result of another column by :obj_rd[1],obj_rd[...]