Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i don't want to use datatable,dataset,dataadapter ..
here is my code..
C#
list<string> lst = new List<string>;
SqlConnection connectToDb = new SqlConnection(mycon);
SqlCommand cmd = new SqlCommand(getsp, connectToDb); 
cmd.CommandType = CommandType.StoredProcedure;
return lst;

how to fill list with data?
Or Is there any other alternative plz provide.
Posted
Updated 8-Mar-14 19:08pm
v2

C#
List<string> temp = new List<string>();
SqlConnection connectToDb = new SqlConnection(mycon);
SqlCommand cmd = new SqlCommand(getsp, connectToDb); 
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

foreach(DataRow dr in dt.Rows)
{
    temp.Add(dr["Name"].ToString());     // your column name instead.
}

return temp;

-KR
 
Share this answer
 
v2
Comments
Sanket Saxena 10-Mar-14 9:19am    
correct
utm 11-Mar-14 7:51am    
if i use datareader in place of datatable and dataadapter .. is it good idea?
Krunal Rohit 11-Mar-14 9:31am    
Of course you can. But I have given this code for the simplicity.
Let's say, a table is made up of rows and columns, so if you want to get the records of the particular table, you'd iterate through all the rows.
That what I've done. !! Simple !

-KR
 
Share this answer
 
Comments
utm 11-Mar-14 7:52am    
if i use datareader in place of datatable and dataadapter .. is it good idea?
Ainy Mughal 11-Mar-14 16:29pm    
Yes you can use data reader in place of data table or data adapter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900