SqlDataAdapter的不填充数据集 [英] SqlDataAdapter does not fill DataSet

查看:373
本文介绍了SqlDataAdapter的不填充数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VS2012和SQL Server防爆preSS 2008年,我煮了我的连接/查询,试图找出为什么我的数据集不被填补。连接成功完成,并没有异常抛出,但适配器没有填满数据集。这是从拉数据库是在同一台电脑,并使用本地主机\ SQLEX $ P $干燥综合征不改变的结果上。感谢您的任何输入!

 的SqlConnection questionConnection =新的SqlConnection(ConfigurationManager.ConnectionStrings [DefaultConnection]的ConnectionString。);
questionConnection.Open();
字符串SQL =SELECT * FROM HRA.dbo.Questions;
SqlDataAdapter的适配器=新的SqlDataAdapter();
的DataSet ds为新的DataSet();
SqlCommand的命令=新的SqlCommand(SQL,questionConnection);
adapter.SelectCommand =命令;
adapter.Fill(DS);
adapter.Dispose();
command.Dispose();
questionConnection.Close();
 

连接字符串:

 <添加名称=DefaultConnection的providerName =System.Data.SqlClient的的connectionString =数据源=编码-PC \ SQLEX $ P $干燥综合征;初始目录= HRA;用户ID = SA;密码= TEST/>
 

解决方案

试试这个:

 的SqlConnection questionConnection =新的SqlConnection(ConfigurationManager.ConnectionStrings [DefaultConnection]的ConnectionString。);
questionConnection.Open();
的DataSet ds为新的DataSet();
字符串SQL =SELECT * FROM HRA.dbo.Questions;
SqlDataAdapter的适配器=新的SqlDataAdapter(SQL,questionConnection);
adapter.Fill(DS);

adapter.Dispose();
command.Dispose();
questionConnection.Close();
 

I'm using VS2012 and SQL Server Express 2008. I've boiled down my connection/query to try and find out why my DataSet is not being filled. The connection is completed successfully, and no exceptions are thrown, but the adapter does not fill the DataSet. The database that this is pulling from is on the same PC and using localhost\SQLEXPRESS does not change the result. Thanks for any input!

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();

Connection String:

<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=CODING-PC\SQLEXPRESS;Initial Catalog=HRA;User ID=sa; Password= TEST" />

解决方案

try this:

SqlConnection questionConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
questionConnection.Open();
DataSet ds = new DataSet();
String sql = "SELECT * FROM HRA.dbo.Questions";
SqlDataAdapter adapter = new SqlDataAdapter(sql, questionConnection);
adapter.Fill(ds);

adapter.Dispose();
command.Dispose();
questionConnection.Close();

这篇关于SqlDataAdapter的不填充数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆