我想知道如何将 sql server 数据库中的列中包含的值复制到Array
or a List
?
我在用着C#
在 Web 应用程序项目 (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());
}
}
将作者姓名填充到列表中的非常基本的示例。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)