0

我已经搜索了网络并搜索了网络,但并没有完全找到我可能遇到的问题。我目前在获取 SqlDataAdapter 来填充 DataSet 时遇到问题。我正在运行 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
}

如果我可以提供更多信息,请告诉我。

4

2 回答 2

3

您需要查询说“从员工中选择密码,其中employee_ID = @EmplID”(参数周围没有单引号)。

于 2010-04-20T17:18:11.343 回答
1

如果您运行此查询,它会返回结果吗?

select Password from Employees where employee_ID = 'EmployeeName'

我的猜测是“EmployeeName”应该是一些传入的值......如果您使用参数,@EmpID 在查询中不应该有单引号。

于 2010-04-20T17:20:46.867 回答