我想知道如何将sql server数据库中的列中包含的值复制到数组或列表中?
我在Web应用程序项目(ASP.NET)中使用C#…
我在Web应用程序项目(ASP.NET)中使用C#…
提前致谢
@H_404_5@解决方法
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()); } }
将作者姓名填入List的非常基本的示例.
@H_404_5@ @H_404_5@