CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    192

    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()

  2. #2
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    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()

  3. #3
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: Update Statement

    You're only searching for " '". You probably have a "'" and are missing it.

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    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
  •  





Click Here to Expand Forum to Full Width

Featured