解决方法@H_301_7@
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的非常基本的示例.
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的非常基本的示例.