Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL statements in c#.net
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01197315
Message ID:
01197316
Vues:
17
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform