>I'm trying to do a simple query from the 'NorthWind' Database 'Employee' table to find a particular record.
>
>I can get all records but when i try to use the WHERE clause i get errors. i am using following:
>
>string ConnString = "server = \"myserver\";uid=sa;pwd=; Initial Catalog = Northwind";
>
>SqlConnection Connection = new SqlConnection (ConnString);
>Connection.Open();
>
>string mykey = this.tbxUserName.text.ToString();
>
>string selectcmd = "SELECT EmployeeID,LastName,FirstName FROM Employees WHERE FirstName = mykey";
>
>SqlCommand command = new SqlCommand(selectcmd,Connection);
>
>SqlDataReader reader = command.ExecuteReader ();
Either use "where FirstName = '" + myKey + "'"
or try to pass myKey as a parameter. Right now you're creating string as is and myKey is not evaluated.
Parameter symbol for Oracle in DataSet Thread #
1193338 Message #
1193338
If it's not broken, fix it until it is.
My Blog