Results 1 to 3 of 3

Thread: [RESOLVED] Update Statement - DatagridView

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2021
    Posts
    71

    Resolved [RESOLVED] Update Statement - DatagridView

    Hi,

    In the Update Statement code - I receive the error message:

    Incorrect Syntax near 'flattype'



    Code:
     For i As Integer = 0 To DgUnitsUp.Rows.Count - 1 Step +1
    
                    query = "UPDATE dbo.tblunits SET flattype=@flattype, units=@units, rentamt=@rentamt, vacant=@vacant, tenantregID=@tenantregID (flattype, units, rentamt, vacant, tenantregID) WHERE propertyID=@propertyID and unitID=@unitID"
                    cmd = New SqlCommand(query, conn1)
    
                    cmd.Parameters.AddWithValue("@flattype", DgUnitsUp.Rows(i).Cells(6).Value.ToString())
                    cmd.Parameters.AddWithValue("@units", DgUnitsUp.Rows(i).Cells(1).Value.ToString())
                    cmd.Parameters.AddWithValue("@rentamt", DgUnitsUp.Rows(i).Cells(2).Value.ToString())
                    cmd.Parameters.AddWithValue("@vacant", DgUnitsUp.Rows(i).Cells(3).Value.ToString())
                    cmd.Parameters.AddWithValue("@tenantregID", DgUnitsUp.Rows(i).Cells(4).Value.ToString())
                    cmd.Parameters.AddWithValue("@propertyID", DgUnitsUp.Rows(i).Cells(0).Value.ToString())
                    cmd.Parameters.AddWithValue("@UnitID", DgUnitsUp.Rows(i).Cells(9).Value.ToString())
    
    
                    cmd.ExecuteNonQuery()
    
                Next
    Any help will be appreciated!

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Update Statement - DatagridView

    This is invalid syntax for an update statement, remove it:
    Code:
    (flattype, units, rentamt, vacant, tenantregID)
    This is likely an artifact from copying/pasting an insert statement.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2021
    Posts
    71

    Re: Update Statement - DatagridView

    Thanks

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