Click here to Skip to main content
13,086,019 members (83,989 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i am working on visual studio framework to manipulate my database using 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
Updated 1-Jan-13 2:00am
ridoy 1-Jan-13 9:15am
what error you get on that?
Rate this: bad
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+"'"; 
Abhinav S 1-Jan-13 10:12am
May be a good catch. 5.
abbasnafiu 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";
OleDbCommand stCmd2 = new OleDbCommand(stUpd, myConnection2);

after debugging it highlights stCmd2.ExecuteNonQuery();

and the error statement is: THE UPPDATE SYNTAX IS INCORRECT
OriginalGriff 1-Jan-13 16:37pm
You missed a closing quote:
Text + "',Sachs='"+txtSch.Text + " where
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
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 -[^].

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100