c# - 读取数组或列表中的 SQL Server 列

标签 c# asp.net sql-server

我想知道如何将 sql server 数据库中列中包含的值复制到 ArrayList 中? 我在 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/

相关文章:

c# - FileHelpers -- 只读取第 N 列

c# - 为什么在字符串中使用引号的javascript转义字符需要\\' instead of\'

asp.net - 使用 Entity Framework 进行部署后数据库更改的最佳实践

asp.net - "<"在 ASP.NET 的文本框中 --> 如何允许它?

sql - 对计算日期字段的操作

sql - 如何减小空间索引数据的大小

sql - 在 sql 中跟踪记录随时间的更新有哪些最佳实践?

c# - 从 C# 代码隐藏触发 Javascript

c# - 在阻塞的 UI 线程中处理 Windows 消息?

asp.net - 如何以ASP.NET形式使用gmail SMTP