473,396 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why ExecuteNonQuery() cannot execute UPDATE command

Hi, everybody,
I am rusty with VB. In the following code,
------------------------------------------------------
Dim dbCmd1 As OleDbCommand = New OleDbCommand("UPDATE
tblLogin SET Password = '1'") ' WHERE UserID = 'Admin'")
Dim dbCmd1 As OleDbCommand = New OleDbCommand("SELECT *
FROM tblLogin WHERE UserID = 'Admin'")
'" + g_userID + "'")
dbCmd1.Connection = g_loginConn
dbCmd1.Connection = g_loginConn
#1: dbCmd.ExecuteNonQuery() 'update syntax error
#2: dbCmd.ExecuteNonQuery() 'ok

-------------------------------------------------------------
the statement at line #1 causes a "update syntax error" while
the statement at
line #2 is OK. Does the ExecuteNonQuery() cannot execute the Update
command or
for some other reasons? I am very appreciated if someone give me some
hints.

May 16 '07 #1
6 13164

I am very sorry for my carelessness. The above code is incorrect. I
rewrite the code as the following,

------------------------------------------------------
Dim dbCmd1 As OleDbCommand = New OleDbCommand("UPDATE
tblLogin SET Password = '1'")
Dim dbCmd2 As OleDbCommand = New OleDbCommand("SELECT *
FROM tblLogin)
dbCmd1.Connection = g_loginConn
dbCmd2.Connection = g_loginConn
#1: dbCmd1.ExecuteNonQuery() 'update syntax error
#2: dbCmd2.ExecuteNonQuery() 'ok

-------------------------------------------------------------
But the line #1 still cannot be executed and the compiler gives a
"Update syntax error" message, while the line #2
is OK. Why?

May 16 '07 #2
Dim dbCmd1 As OleDbCommand = New OleDbCommand("UPDATE
tblLogin SET Password = '1'")
When I change the column name "Password" to "Pwd", the error
disappears!
Does the "Password" name conflicts to some reserved name?
Damn! It took me nearly a whole day to solve this problem.

May 16 '07 #3
On May 16, 1:27 am, ssailor <ssailor...@hotmail.comwrote:
Dim dbCmd1 As OleDbCommand = New OleDbCommand("UPDATE
tblLogin SET Password = '1'")

When I change the column name "Password" to "Pwd", the error
disappears!
Does the "Password" name conflicts to some reserved name?
Damn! It took me nearly a whole day to solve this problem.
You didn't say what SQL Provider you are using, but the column
referenced in an UPDATE statement SET command MUST be EXACTLY the same
as the name of the column in the Providers "back-end". What made you
think the name of the column was "Password" as opposed to "Pwd"?

PS: Case doesn't usually matter.

May 16 '07 #4
On May 16, 8:39 am, z...@construction-imaging.com wrote:
On May 16, 1:27 am, ssailor <ssailor...@hotmail.comwrote:
Dim dbCmd1 As OleDbCommand = New OleDbCommand("UPDATE
tblLogin SET Password = '1'")
When I change the column name "Password" to "Pwd", the error
disappears!
Does the "Password" name conflicts to some reserved name?
Damn! It took me nearly a whole day to solve this problem.

You didn't say what SQL Provider you are using, but the column
referenced in an UPDATE statement SET command MUST be EXACTLY the same
as the name of the column in the Providers "back-end". What made you
think the name of the column was "Password" as opposed to "Pwd"?

PS: Case doesn't usually matter.
Perhaps he meant he changed the database column to "Pwd" as well as
the query? If so, the OP should have been able to use [Password] in
the query to refer to a column named the same as the protected keyword
"Password."

Thanks,

Seth Rowe

May 16 '07 #5
On May 16, 9:23 am, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On May 16, 8:39 am, z...@construction-imaging.com wrote:


On May 16, 1:27 am, ssailor <ssailor...@hotmail.comwrote:
Dim dbCmd1 As OleDbCommand = New OleDbCommand("UPDATE
tblLogin SET Password = '1'")
When I change the column name "Password" to "Pwd", the error
disappears!
Does the "Password" name conflicts to some reserved name?
Damn! It took me nearly a whole day to solve this problem.
You didn't say what SQL Provider you are using, but the column
referenced in an UPDATE statement SET command MUST be EXACTLY the same
as the name of the column in the Providers "back-end". What made you
think the name of the column was "Password" as opposed to "Pwd"?
PS: Case doesn't usually matter.

Perhaps he meant he changed the database column to "Pwd" as well as
the query? If so, the OP should have been able to use [Password] in
the query to refer to a column named the same as the protected keyword
"Password."
You're right, I forgot Password is a keyword. That's one reason why,
when I am generating queries on the fly in VB code, I like to enclose
every column and table reference with square brackets.

May 16 '07 #6

rowe_newsgroups write:
On May 16, 8:39 am, z...@construction-imaging.com wrote:
On May 16, 1:27 am, ssailor <ssailor...@hotmail.comwrote:
Dim dbCmd1 As OleDbCommand = New OleDbCommand("UPDATE
tblLogin SET Password = '1'")
When I change the column name "Password" to "Pwd", the error
disappears!
Does the "Password" name conflicts to some reserved name?
Damn! It took me nearly a whole day to solve this problem.
You didn't say what SQL Provider you are using, but the column
referenced in an UPDATE statement SET command MUST be EXACTLY the same
as the name of the column in the Providers "back-end". What made you
think the name of the column was "Password" as opposed to "Pwd"?

PS: Case doesn't usually matter.

Perhaps he meant he changed the database column to "Pwd" as well as
the query? If so, the OP should have been able to use [Password] in
the query to refer to a column named the same as the protected keyword
"Password."
Right, this is what I meant.
I used the Access database and created the table in the Access. I
didn't know the cloumn can be quoted in "[ ]". Thank you!

May 17 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: NETDeveloper | last post by:
Hi, I almost have my nested datagrid working properly. I created a datagrid on a user control and dropped that onto another datagrid. At first, I noticed when I was stepping through the code,...
4
by: Chris | last post by:
I posted this in the C# language group, then thought it might be more appropriate in this group. I would not cross-post except I want the answer so badly. I built small C# Web and Web Service...
1
by: Nathan | last post by:
Hi, I want to change a field in a database directly using an update command, not by changing a dataset first and then updating. I'm trying to use a command similar to this: ...
3
by: A_PK | last post by:
Could anyone pls guide me what is wrong with my Update Command Dim signbyte As Byte() signbyte = GetByteArray() ' i create this function to return ByteArray Try Dim cmd As New SqlCeCommand...
7
by: Risen | last post by:
Hi,all, I want to execute SQL command " DROP DATABASE mydb" and "Restore DATABASE ....." in vb.net 2003. But it always shows error. If any body can tell me how to execute sql command as above?...
4
by: William LaMartin | last post by:
In the past, I have filled a datagrid with data from an Access database table using a data adapter and dataset, where I used the OleDbCommandBuilder to have the program create the insert, delete...
2
by: TJ | last post by:
Hi All, I am having some trouble. I have created a database via the new database option inside VWD2005. Then and table or two. I have been able to perform INSERT and SELECT operations on...
3
by: kpeeroo | last post by:
Private Function AddCompanyOvertime() As Integer Dim companyID As Integer = GetCompanyID() Console.WriteLine(companyID) Dim paramCompanyID As New SqlParameter("@CompanyID",...
1
by: syminder | last post by:
Hi guy, I using the batch program to trigger specific main class in JAR. It is simplest JAVA -cp %classpath% Main_class cmd instruction. Initialy the jdk is not installing cause JAVA command...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.