C# and Access Query

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

New to C# and can't quite figure out how to write my
update query correctly...(this is actually ASP.NET using
C# trying to work with Access - wasn't sure where to post)

UPDATE customer SET last_name = "" + txtLast_Name.Text
+ "";

Access needs quotes around it's strings. I can't figure
out how to do it.

I've tried this:
UPDATE customer SET last_name = "" + txtLast_Name.Text
+ """;

and this:
UPDATE customer SET last_name = "/" + txtLast_Name.Text
+ "/"";

none work...

Thanks!
 
Not sure where you are putting this command but for an example, when
building a string, you can simply insert the tick mark.
Examples:
String s = "Update customer SET last_name = '" + myvariable + "'";
or even better:
String s = String.Format("Update customer SET last_name = '{0}'",
myvariable);

HTH....
 
Chris said:
New to C# and can't quite figure out how to write my
update query correctly...(this is actually ASP.NET using
C# trying to work with Access - wasn't sure where to post)

UPDATE customer SET last_name = "" + txtLast_Name.Text
+ "";

Access needs quotes around it's strings. I can't figure
out how to do it.

You don't - you use parameters instead. That way you don't have to do
any quoting, and you don't risk a SQL injection attack.

See http://www.pobox.com/~skeet/csharp/faq/#db.parameters
 
Back
Top