Reputation: 3101
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.
Upvotes: 0
Views: 1320
Reputation: 6540
If you run this query does it return results?
select Password from Employees where employee_ID = 'EmployeeName'
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.
Upvotes: 1
Reputation: 8018
You need the query to say "select Password from Employees where employee_ID = @EmplID" (no single-quotes around the parameter).
Upvotes: 3