Answered by:
How to convert SQLce Datareader values to list?

Question
-
Hi all,
i want to know can we convert DataReader values to list without using foreach or loops.
i mean can we assign DataReader values to List directly??
or we have to add one bye one them using loops???
sumitk
Monday, October 22, 2012 7:06 AM
Answers
-
-
Hi,
DataRader is a forward and read only data one by one.So to add records to list one by one we have to use while loop.
eg:
SqlceDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
// write your code here
}
PS.Shakeer Hussain
Monday, October 22, 2012 7:17 AM -
Hi Sumit,
By using dataset also you have to use while or for loop to add data to list ..
SqlceDataAdapter da=new SqlceDataAdapter(sqlQuery); Dataset ds=new DataSet(); da.Fill(ds); for(int i=0;i<ds.Tables[0].Rows.Count;i++) { li.Add(ds.Tables[0].Rows[i]["columnName"].ToString()); }
PS.Shakeer Hussain
Monday, October 22, 2012 8:57 AM
All replies
-
-
Hi Sumitk,
you need to use look structure for adding values in list. you can read your data reader until it reaches to end and one by one adding.
If there are any other library available for the same, it would be doing internally this only.
Thanks and Regards, Shailesh B. Davara
Monday, October 22, 2012 7:16 AM -
Hi,
DataRader is a forward and read only data one by one.So to add records to list one by one we have to use while loop.
eg:
SqlceDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
// write your code here
}
PS.Shakeer Hussain
Monday, October 22, 2012 7:17 AM -
thanx for your replaycan we use Dataset insteadof dataReader for achieve my goal??
sumitk
Monday, October 22, 2012 7:31 AM -
Hi Sumit,
By using dataset also you have to use while or for loop to add data to list ..
SqlceDataAdapter da=new SqlceDataAdapter(sqlQuery); Dataset ds=new DataSet(); da.Fill(ds); for(int i=0;i<ds.Tables[0].Rows.Count;i++) { li.Add(ds.Tables[0].Rows[i]["columnName"].ToString()); }
PS.Shakeer Hussain
Monday, October 22, 2012 8:57 AM