Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: c#.
i am working on visual studio framework to manipulate my database using ado.net connectivity this is my update statement
 
string stdupdt = "update std set  name='"+txtNM.Text+"' ,addr= '"+txtAD.Text+"' where id='"+txtID.Text+"'"; 
 
what is wrong with this statement please
Posted 1-Jan-13 1:57am
Edited 1-Jan-13 2:00am
v2
Comments
ridoy at 1-Jan-13 9:15am
   
what error you get on that?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Without knowing anything about teh error message you get, it is very difficult to be sure, but...
 
Probably, you problem is to do with the database definition - you have used an Access reserved word[^] as a column name, and this is likely to confuse Access when you try to update as it isn't expecting to see the word in that context.
In this case, you should not name any column "name" - if you do, then you need to enclose it in square brackets:
string stdupdt = "update std set [name]='"+txtNM.Text+"' ,addr= '"+txtAD.Text+"' where id='"+txtID.Text+"'"; 
  Permalink  
Comments
Abhinav S at 1-Jan-13 10:12am
   
May be a good catch. 5.
abbasnafiu at 1-Jan-13 15:35pm
   
this is my code statement OleDbConnection myConnection2 = new OleDbConnection(con); //string stUpd = "update std2 +"set names=+txtNm.Text+ ,schs= +txtSch.Text+" + where ids=+txtId.Text+"; string stUpd = "update std2 set [names]='" + txtNm.Text + "' ,schs= '" + txtSch.Text + " where ids=txtId.Text"; myConnection2.Open(); OleDbCommand stCmd2 = new OleDbCommand(stUpd, myConnection2); stCmd2.ExecuteNonQuery(); myConnection2.Close(); MessageBox.Show("updated"); after debugging it highlights stCmd2.ExecuteNonQuery(); and the error statement is: THE UPPDATE SYNTAX IS INCORRECT
OriginalGriff at 1-Jan-13 16:37pm
   
You missed a closing quote: Text + "',Sachs='"+txtSch.Text + " where Becomes: Text + "',Sachs='"+txtSch.Test + "' where But please don't do it like that - you are leaving yourself open to a deliberate or accidental SQL Injection Attack which can destroy your entire database. Use parameterized queries instead.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Make sure Id is not numeric.
 
Try and debug this code. When execution comes to this line, pick up the query, paste in management studio and run it.
See what type of error you get. It should give you a better idea of how to fix this problem.
 
Also note that passing parameters directly into a query can lead to security concerns.
Try and use parameters - http://csharp-station.com/Tutorial/AdoDotNet/Lesson06[^].
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 390
1 Shai Vashdi 349
2 Sergey Alexandrovich Kryukov 325
3 OriginalGriff 265
4 Peter Leow 171
0 Sergey Alexandrovich Kryukov 8,979
1 OriginalGriff 5,280
2 Peter Leow 4,010
3 Maciej Los 3,535
4 Abhinav S 3,263


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid