0

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 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

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

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.