读取数组或列表中的SQL Server列 [英] Reading SQL Server Column in an Array or List
本文介绍了读取数组或列表中的SQL Server列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何将sql服务器数据库中的列中包含的值复制到 Array
或 List
中?我在Web应用程序项目(ASP.NET)中使用 C#
...
I want to know how to copy the values contained in a column in sql server database into an Array
or a List
?
I'm using C#
in a Web Application Project(ASP.NET)...
预先感谢
推荐答案
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<string> authorNames = new List<string>();
foreach(DataRow row in ds.Tables["authors"].Rows)
{
authorNames.Add(row["name"].ToString());
}
}
一个非常基本的示例,用于将作者姓名填充到列表中.
Very basic example to fill author names into List.
这篇关于读取数组或列表中的SQL Server列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文