【发布时间】:2012-10-30 12:05:31
【问题描述】:
我正在使用 VS2012 和 SQL Server Express 2008。我已经总结了我的连接/查询,试图找出我的 DataSet 没有被填充的原因。连接成功完成,没有抛出异常,但是适配器没有填写DataSet。从中提取的数据库位于同一台 PC 上,使用 localhost\SQLEXPRESS 不会改变结果。感谢您的任何意见!
SqlConnection questionConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
questionConnection.Open();
String sql = "SELECT * FROM HRA.dbo.Questions";
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlCommand command = new SqlCommand(sql, questionConnection);
adapter.SelectCommand = command;
adapter.Fill(ds);
adapter.Dispose();
command.Dispose();
questionConnection.Close();
连接字符串:
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=CODING-PC\SQLEXPRESS;Initial Catalog=HRA;User ID=sa; Password= TEST" />
【问题讨论】:
-
检查数据有没有............你会得到数据在ds.Tables[0]
标签: c# sql sql-server ado.net