读取数组或列表中的SQL Server列
我想知道如何将sql server数据库中的列中包含的值复制到Array
或List
? 我在Web应用程序项目(ASP.NET)中使用C#
…
提前致谢
using (SqlConnection cnn = new SqlConnection("server=(local);database=pubs;Integrated Security=SSPI")) { SqlDataAdapter da = new SqlDataAdapter("select name from authors", cnn); DataSet ds = new DataSet(); da.Fill(ds, "authors"); List authorNames = new List (); foreach(DataRow row in ds.Tables["authors"].Rows) { authorNames.Add(row["name"].ToString()); } }
将作者姓名填入List的非常基本的示例。
看看这是否有帮助http://blog.sqlauthority.com/2009/11/25/sql-server-comma-separated-values-csv-from-table-column/
首先,您必须填充dataTable中的记录,然后遍历dataTable的所有行,并将每个记录逐个添加到数组列表中。 请查看: http : //www.dreamincode.net/code/snippet1864.htm
ArrayList obj = new ArrayList(); for(int x= 0;x
- UserControl中的Web控件是否为空?
- 无法加载文件或程序集“AxInterop.WMPLib”或其依赖项之一。 参数不正确。
- 这两个HttpContext.Current.Session和Session – asp.net 4.0有什么区别
- 使用分页刮取ASP.NET网站
- WebAPI DataMember通过application / x-www-form-urlencoded进行de / serial化时不使用的名称
- 相同类型的Object的InvalidCastException – 自定义控件加载
- 用html保存字符串作为图像
- 以编程方式将文件添加到Kentico媒体库
- 如何从Action Method with Array属性返回Json?