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

"select Password from Employees where 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 に答える