Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL statements in c#.net
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01197315
Message ID:
01197316
Views:
16
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform