如何从数据库中填写列表? [英] How Do I Fill List From Database ?

查看:117
本文介绍了如何从数据库中填写列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想使用datatable,dataset,dataadapter ..

这里是我的代码..

i don't want to use datatable,dataset,dataadapter ..
here is my code..

list<string> lst = new List<string>;
SqlConnection connectToDb = new SqlConnection(mycon);
SqlCommand cmd = new SqlCommand(getsp, connectToDb); 
cmd.CommandType = CommandType.StoredProcedure;
return lst;



如何用数据填充列表?

或者是否有其他替代plz提供。


how to fill list with data?
Or Is there any other alternative plz provide.

推荐答案

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


-KR


没有数据表是不可能的,数据集或数据适配器。你必须使用其中任何一个。



http://stackoverflow.com/questions/15416088/how-to-populate-list-from-sql-server-database- in-asp-net-using-json-and-ajax [ ^ ]



< a href =http://forums.asp.net/t/1672689.aspx> http://forums.asp.net/t/1672689.aspx [ ^ ]
it is not possible without Data Table, Data Set or Data Adapter. You have to use any of these.

http://stackoverflow.com/questions/15416088/how-to-populate-list-from-sql-server-database-in-asp-net-using-json-and-ajax[^]

http://forums.asp.net/t/1672689.aspx[^]


这篇关于如何从数据库中填写列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆