C# SqlDataAdapter 未填充数据集
我在网上搜索了又搜索,但没有完全找到我遇到的情况。我目前在获取 SqlDataAdapter 来填充数据集时遇到问题。我正在运行 Visual Studio 2008,并且查询正在发送到 SqlServer 2008 的本地实例。如果我运行查询 SqlServer,它确实会返回结果。 代码如下:
string theQuery = "select Password from Employees where employee_ID = '@EmplID'";
SqlDataAdapter theDataAdapter = new SqlDataAdapter();
theDataAdapter.SelectCommand = new SqlCommand(theQuery, conn);
theDataAdapter.SelectCommand.Parameters.Add("@EmplID", SqlDbType.VarChar).Value = "EmployeeName";
theDataAdapter.Fill(theSet);
读取数据集的代码:
foreach (DataRow theRow in theSet.Tables[0].Rows)
{
//process row info
}
如果我可以提供更多信息,请告诉我。
I have searched the net and searched the net only to not quite find the probably I am running into. I am currently having an issue getting a SqlDataAdapter to populate a DataSet. I am running Visual Studio 2008 and the query is being sent to a local instance of SqlServer 2008. If I run the query SqlServer, it does return results.
Code is as follows:
string theQuery = "select Password from Employees where employee_ID = '@EmplID'";
SqlDataAdapter theDataAdapter = new SqlDataAdapter();
theDataAdapter.SelectCommand = new SqlCommand(theQuery, conn);
theDataAdapter.SelectCommand.Parameters.Add("@EmplID", SqlDbType.VarChar).Value = "EmployeeName";
theDataAdapter.Fill(theSet);
The code to read the dataset:
foreach (DataRow theRow in theSet.Tables[0].Rows)
{
//process row info
}
If there is any more info I can supply please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要查询“从员工中选择密码,其中employee_ID = @EmplID”(参数周围没有单引号)。
You need the query to say "select Password from Employees where employee_ID = @EmplID" (no single-quotes around the parameter).
如果运行此查询,它会返回结果吗?
我的猜测是“EmployeeName”应该是一些传递的值......
如果您使用参数,则 @EmpID 在查询中不应包含单引号。
If you run this query does it return results?
My guess is "EmployeeName" should be some passed in value....
and @EmpID shouldn't have single quotes around it in the query if you're using a parameter.