我想知道如何将 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<string> authorNames = new List<string>();
foreach(DataRow row in ds.Tables["authors"].Rows)
{
authorNames.Add(row["name"].ToString());
}
}
将作者姓名填入列表的非常基本的示例。
关于c# - 读取数组或列表中的 SQL Server 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6572101/