-
August 14th, 2012, 10:30 AM
#1
Update Statement
Hi,
I receive the error -
Incorrect syntax
Unclosed syntax near 's'
Unclosed quotation mark after character string ".
Code:
query = "UPDATE dbo.TblPracExclude SET " & _
"prac_enabled = '" & DgvPracExcl.Rows(e.RowIndex).Cells(4).Value & "', " & _
"Notes = '" & Nz(Replace(DgvPracExcl.Rows(e.RowIndex).Cells(5).Value, " '", "''")) & "', " & _
"SysDatetime = '" & DateTime.Now.ToString("dd\-MMMM\-yyyy HH:mm:ss") & "', " & _
"WHERE prac_no = " & _
DgvPracExcl.Rows(e.RowIndex).Cells(0).Value & ""
any help please
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
-
August 14th, 2012, 12:53 PM
#2
Re: Update Statement
Change you update to use Parameters. That way you will avoid quoting issues. Also it makes it more readable.
Code:
query = "UPDATE dbo.TblPracExclude SET prac_enabled = @prac_enabled, Notes = @Notes, SysDatetime = @SysDateTime WHERE prac_no = @prac_no"
cmd = New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@prac_enabled",DgvPracExcl.Rows(e.RowIndex).Cells(4).Value)
cmd.Parameters.AddWithValue("@Notes",DgvPracExcl.Rows(e.RowIndex).Cells(5).Value)
cmd.Parameters.AddWithValue("@SysDateTime",DateTime.Now)
cmd.Parameters.AddWithValue("@prac_no",DgvPracExcl.Rows(e.RowIndex).Cells(0).Value)
cmd.ExecuteNonQuery()
-
August 16th, 2012, 08:21 PM
#3
Re: Update Statement
You're only searching for " '". You probably have a "'" and are missing it.
-
August 17th, 2012, 03:48 AM
#4
Re: Update Statement
#1 problem here is if the notes test has a ' in it.. IE: " It's difficult to find a note that doesn't use the single quote at least once."
This then causes problems with the Query's ... two solutions... Drop them out.. or Double them up....
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|