473,545 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax error with Update command - how to use?

Well, here is some weirdness. First, I noticed that I
have 2 Set keywords (silly me). so I removed the
2nd "Set" but still got a syntax error. Then I removed
the Where clause, and now it works perfectly. Is this
correct? Or am I just getting lucky? I'm not completely
clear on the fundamentals here. I update the table in my
dataset, then I update the table on the server through the
dataAdapter. I think I have a handle on the dataAdapter
part. But wait! I think I get it. I specify which row
to update in the table in the dataset, then update the
server table. Man, dotnet is great. It's so simple.

Jerry

-----Original Message-----
Greeting,

I am trying to update a detail table that does not have a
unique key (that is the exercise). With the code below I
am getting the error message "Incorrect syntax near
keyword Set" (note: sql code is all on one line). I may
be guilty of tring to use Com ADO syntax. In the Where
clause I am using declared variables instead of parameter
vars. Is that my error? Please could someone correct my
syntax error below?
----------------------------------------------------------
setting intID, str1 and str2 up here --- then
....
Dim sqlDA As SqlDataAdapter = New SqlDataAdapter( "Select *From tbl2", conn)
sqlDA.UpdateCo mmand = New SqlCommand("Upd ate tbl2 Set fld1= @prm1, Set fld2 = @prm2 Where (ID = " & intID & " And
fld1 = '" & str1 & "' fld2 = '" & str2 & "')", conn)
sqlDA.UpdateCo mmand.CommandTy pe = CommandType.Tex t

Try
conn.Open()
Dim sqlParm As New SqlParameter
sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter(" @prm1", SqlDbType.VarCh ar, 50, "fld1"))
sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter(" @prm2", SqlDbType.VarCh ar, 50, "fld2"))
dr = ds1.Tables("tbl 2").Rows(5)
dr(0) = CType(txtID.Tex t, Integer)
dr(1) = txtfld1.Text)
dr(2) = txtfld2.Text
sqlDA.Update(ds 1, "tbl2") <----> errors out here <-----
conn.Close()
Catch...
-------------------------------------------------------

Thanks in advance,
Jerry
.

Nov 20 '05 #1
3 3108
LAL
You need to add "AND" between your 2nd & 3rd where conditions
"Jerry" <an*******@disc ussions.microso ft.com> wrote in message
news:b6******** *************** *****@phx.gbl.. .
Well, here is some weirdness. First, I noticed that I
have 2 Set keywords (silly me). so I removed the
2nd "Set" but still got a syntax error. Then I removed
the Where clause, and now it works perfectly. Is this
correct? Or am I just getting lucky? I'm not completely
clear on the fundamentals here. I update the table in my
dataset, then I update the table on the server through the
dataAdapter. I think I have a handle on the dataAdapter
part. But wait! I think I get it. I specify which row
to update in the table in the dataset, then update the
server table. Man, dotnet is great. It's so simple.

Jerry

-----Original Message-----
Greeting,

I am trying to update a detail table that does not have a
unique key (that is the exercise). With the code below I
am getting the error message "Incorrect syntax near
keyword Set" (note: sql code is all on one line). I may
be guilty of tring to use Com ADO syntax. In the Where
clause I am using declared variables instead of parameter
vars. Is that my error? Please could someone correct my
syntax error below?
----------------------------------------------------------
setting intID, str1 and str2 up here --- then
....
Dim sqlDA As SqlDataAdapter = New SqlDataAdapter( "Select

*
From tbl2", conn)
sqlDA.UpdateCo mmand = New SqlCommand("Upd ate tbl2 Set

fld1
= @prm1, Set fld2 = @prm2 Where (ID = " & intID & " And
fld1 = '" & str1 & "' fld2 = '" & str2 & "')", conn)
sqlDA.UpdateCo mmand.CommandTy pe = CommandType.Tex t

Try
conn.Open()
Dim sqlParm As New SqlParameter
sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter(" @prm1", SqlDbType.VarCh ar, 50, "fld1"))
sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter(" @prm2", SqlDbType.VarCh ar, 50, "fld2"))
dr = ds1.Tables("tbl 2").Rows(5)
dr(0) = CType(txtID.Tex t, Integer)
dr(1) = txtfld1.Text)
dr(2) = txtfld2.Text
sqlDA.Update(ds 1, "tbl2") <----> errors out here <-----
conn.Close()
Catch...
-------------------------------------------------------

Thanks in advance,
Jerry
.

Nov 20 '05 #2
Thanks. I fixed that. And, of course, without the Where
clause I get the same values for all the rows. But now I
get a new error message that the params in the Where
clause are not being supplied. Here is what I have now:
sqlDA.UpdateCom mand = New SqlCommand("Upd ate tbl2 Set fld1
= @prm1, fld2 = @prm2 Where (ID = @ID And fld1 = @fld1 And
fld2 = @fld2)", conn)

-------------------------------------------------------
---params with new values---------this works OK without
Where clause----------

sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ prm1", SqlDbType.VarCh ar, 50, "fld1"))
sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ prm2", sqlDbType.VarCh ar,50, "fld2"))

-----------------------------------------------------
-----------------------------------------------------

---params for Where Clause with original values from
variables---------
---message says these params not being supplied to Where
clause''---------------

sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ ID", SqlDbType.BigIn t, 8, conID.ToString) )
sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ fld1", SqlDbType.VarCh ar, 50, strfld1))
sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ fld2", SqlDbType.VarCh ar, 50, strfld2))
-----------------------------------------------------

Am I doing this correctly to add the old values to these
params in the Where clause?

Thanks,
Jerry

-----Original Message-----
You need to add "AND" between your 2nd & 3rd where conditions

"Jerry" <an*******@disc ussions.microso ft.com> wrote in messagenews:b6******* *************** ******@phx.gbl. ..
Well, here is some weirdness. First, I noticed that I
have 2 Set keywords (silly me). so I removed the
2nd "Set" but still got a syntax error. Then I removed
the Where clause, and now it works perfectly. Is this
correct? Or am I just getting lucky? I'm not completely clear on the fundamentals here. I update the table in my dataset, then I update the table on the server through the dataAdapter. I think I have a handle on the dataAdapter
part. But wait! I think I get it. I specify which row
to update in the table in the dataset, then update the
server table. Man, dotnet is great. It's so simple.

Jerry

>-----Original Message-----
>Greeting,
>
>I am trying to update a detail table that does not have a >unique key (that is the exercise). With the code below I >am getting the error message "Incorrect syntax near
>keyword Set" (note: sql code is all on one line). I may >be guilty of tring to use Com ADO syntax. In the Where
>clause I am using declared variables instead of parameter >vars. Is that my error? Please could someone correct my >syntax error below?
>------------------------------------------------------- --- >setting intID, str1 and str2 up here --- then
>....
>Dim sqlDA As SqlDataAdapter = New SqlDataAdapter ("Select
*
>From tbl2", conn)
>sqlDA.UpdateCo mmand = New SqlCommand("Upd ate tbl2 Set

fld1
>= @prm1, Set fld2 = @prm2 Where (ID = " & intID & " And
>fld1 = '" & str1 & "' fld2 = '" & str2 & "')", conn)
>sqlDA.UpdateCo mmand.CommandTy pe = CommandType.Tex t
>
>Try
> conn.Open()
> Dim sqlParm As New SqlParameter
> sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
>SqlParameter(" @prm1", SqlDbType.VarCh ar, 50, "fld1"))
>sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
>SqlParameter(" @prm2", SqlDbType.VarCh ar, 50, "fld2"))
> dr = ds1.Tables("tbl 2").Rows(5)
> dr(0) = CType(txtID.Tex t, Integer)
> dr(1) = txtfld1.Text)
> dr(2) = txtfld2.Text
> sqlDA.Update(ds 1, "tbl2") <----> errors out here <--

--- > conn.Close()
>Catch...
>-------------------------------------------------------
>
>Thanks in advance,
>Jerry
>.
>

.

Nov 20 '05 #3
OK. Here is my fix: I copied the Windows generated code
for the update command of the table that does have a
unique field. Had to include

System.Data.Par ameterDirection .Input,

and

System.Data.Dat aRowVersion.Ori ginal

I'm sure there is a less verbose way to add these clauses,
but this works for now.

Jerry

-----Original Message-----
Thanks. I fixed that. And, of course, without the Where
clause I get the same values for all the rows. But now I
get a new error message that the params in the Where
clause are not being supplied. Here is what I have now:
sqlDA.UpdateCo mmand = New SqlCommand("Upd ate tbl2 Set fld1= @prm1, fld2 = @prm2 Where (ID = @ID And fld1 = @fld1 Andfld2 = @fld2)", conn)

-------------------------------------------------------
---params with new values---------this works OK without
Where clause----------

sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ prm1", SqlDbType.VarCh ar, 50, "fld1"))
sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ prm2", sqlDbType.VarCh ar,50, "fld2"))

-----------------------------------------------------
-----------------------------------------------------

---params for Where Clause with original values from
variables---------
---message says these params not being supplied to Where
clause''---------------

sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ ID", SqlDbType.BigIn t, 8, conID.ToString) )sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ fld1", SqlDbType.VarCh ar, 50, strfld1))
sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
SqlParameter("@ fld2", SqlDbType.VarCh ar, 50, strfld2))
-----------------------------------------------------

Am I doing this correctly to add the old values to these
params in the Where clause?

Thanks,
Jerry

-----Original Message-----
You need to add "AND" between your 2nd & 3rd whereconditions


"Jerry" <an*******@disc ussions.microso ft.com> wrote in

message
news:b6****** *************** *******@phx.gbl ...
Well, here is some weirdness. First, I noticed that I
have 2 Set keywords (silly me). so I removed the
2nd "Set" but still got a syntax error. Then I removed
the Where clause, and now it works perfectly. Is this
correct? Or am I just getting lucky? I'm notcompletely clear on the fundamentals here. I update the table inmy dataset, then I update the table on the server throughthe dataAdapter. I think I have a handle on the dataAdapter part. But wait! I think I get it. I specify which row to update in the table in the dataset, then update the
server table. Man, dotnet is great. It's so simple.

Jerry
>-----Original Message-----
>Greeting,
>
>I am trying to update a detail table that does nothave a >unique key (that is the exercise). With the codebelow I >am getting the error message "Incorrect syntax near
>keyword Set" (note: sql code is all on one line). Imay >be guilty of tring to use Com ADO syntax. In the Where >clause I am using declared variables instead ofparameter >vars. Is that my error? Please could someone correctmy >syntax error below?
>------------------------------------------------------ ----
>setting intID, str1 and str2 up here --- then
>....
>Dim sqlDA As SqlDataAdapter = New SqlDataAdapter("Select *
>From tbl2", conn)
>sqlDA.UpdateCo mmand = New SqlCommand("Upd ate tbl2 Set
fld1
>= @prm1, Set fld2 = @prm2 Where (ID = " & intID & "
And >fld1 = '" & str1 & "' fld2 = '" & str2 & "')", conn)
>sqlDA.UpdateCo mmand.CommandTy pe = CommandType.Tex t
>
>Try
> conn.Open()
> Dim sqlParm As New SqlParameter
> sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
>SqlParameter(" @prm1", SqlDbType.VarCh ar, 50, "fld1"))
>sqlParm = sqlDA.UpdateCom mand.Parameters .Add(New
>SqlParameter(" @prm2", SqlDbType.VarCh ar, 50, "fld2"))
> dr = ds1.Tables("tbl 2").Rows(5)
> dr(0) = CType(txtID.Tex t, Integer)
> dr(1) = txtfld1.Text)
> dr(2) = txtfld2.Text
> sqlDA.Update(ds 1, "tbl2") <----> errors out here <- -
--- > conn.Close()
>Catch...
>------------------------------------------------------

- >
>Thanks in advance,
>Jerry
>.
>

.

.

Nov 20 '05 #4

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

Similar topics

6
1920
by: charles | last post by:
The follow SQL expressions don't work in MySQL: UPDATE calendar SET Date = '2004-01-29' WHERE Date < '2004-01-29' AND Done = 0 UPDATE calendar SET Date = '2004-01-29' WHERE ((Date < '2004-01-29') AND (Done = 0)) UPDATE calendar SET Date = '2004-01-29' WHERE (Date < '2004-01-29') AND (Done = 0) UPDATE calendar SET Date = '2004-01-29' WHERE...
5
5124
by: S.Patten | last post by:
Hi, I have a problem with updating a datetime column, When I try to change the Column from VB I get "Incorrect syntax near '942'" returned from '942' is the unique key column value However if I update any other column the syntax is fine
3
3095
by: KevLow | last post by:
Hi, Hope some kind soul can help me out here.. I'm trying to programmatically modify the column headings of a crosstab query such that it can be dynamic based on user specified period (Month Year to Month Year) So far i have tried to use the following code: //
1
3085
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line 112: MM_editCmd.ActiveConnection = MM_editConnection Line 113: MM_editCmd.CommandText = MM_editQuery Line 114: MM_editCmd.Execute
2
4793
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and sql server is my backend server. This error occured whenever i step through and when it reaches rs.update it jux hangs down there and thereafter...
1
13953
by: DaveF | last post by:
Any Ideas as to this error message. I am trying to learn using ms sql server 7.0 Below is the code I am using for an update to a MS Sql Database. <%@ Language=VBScript %> <% Option Explicit %> <html> <head>
0
8292
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new records there is an error "Incorrect syntax near '-'. Must declare the scalar variable "@UserName". I worked out in design view,code is automatically...
4
3214
by: cluce | last post by:
I am getting a syntax error but I cant seem to spot it. need help with this. Its when I click the save button that fires my SQL UPDATE query. thansk in advance 'module level declarations Dim rsNames As ADODB.Recordset Dim cnDb As ADODB.Connection Dim strConnection As String Dim blnAddMode As Boolean
0
1177
by: ewokspy | last post by:
When I perform an Update using a dataadapter I am getting an error stating there is a syntax error in UPDATE command. Here is the Update Command that is in the adapter: UPDATE PAPrintJobs SET (Threaded = ?, PickedUp = ? ) WHERE ( Id = ? AND Owner = ? AND SubmittedDate = ? AND SubmittedTime = ? ); Can anyone spot the error? I'm pretty...
0
7490
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7682
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7780
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6009
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5351
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.