SqlDataReader odr1 = cmd1.ExecuteReader();
if (odr1.Read() == true)
{
ids += odr1[0].ToString();
}
string dr = ids.ToString();
please explain what is meaning of this code?what is the use datareader?
Loading
Amit ChoudharyPosted Feb 27, 2011, 9:32 AM
SqlDataReader is class that behaves like a cursor (we use in databases). It always can be read in forward mode. cmd1.ExecuteReader() return an object of SqlDataReader that contains the record based on your query having initial index at -1.
When you call odr1.Read() method it comes to index 0.
Then next statement odr1[0] return the value at row 0 (comes from index) and column 0(have to pass manually) .
It return a datarow view type object so you need to convert it to string.
Hope you should be very clear about it.
Please mark "Do you like this answer"
Thanks.