views:

262

answers:

2

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.

+2  A: 

You need the query to say "select Password from Employees where employee_ID = @EmplID" (no single-quotes around the parameter).

Tom Cabanski
That was it, thank you very much. I will accept the answer as soon as it lets me.
Wesley
Second set of eyes is all it takes. Sometimes they don't even have to be part of a smart head ;-)
Tom Cabanski
+1  A: 

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.

Germ