I have the following code that will update one field called RCon in sql, does anyone know how i can update a few at the same time?
i would like to update the sql field (called stockdesc)

Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Try
            con.ConnectionString = "Data Source=10.10.0.25;Initial Catalog=RConditions;Persist Security Info=True;User ID=mbish;Password=mbish"
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "update LN2 SET RCon = @RCon where Stkcode = @stkcode"
            cmd.Parameters.AddWithValue("@RCon", Me.txtLine2Rcon.Text)
            cmd.Parameters.AddWithValue("@stkcode", Me.txtStockCode.Text)

            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
        Finally
            con.Close()
        End Try

I have tested below which didn't work

Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Try
            con.ConnectionString = "Data Source=localhost;Initial Catalog=maintsystem;Persist Security Info=True;User ID=mbish;Password=mbish"
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "update Contacts SET (Contactname,company,emailaddress,phonenumber)Values(@Contactnam,@Compname,@emailadd,@phoneum) where Contactid = @contactid"
            cmd.Parameters.AddWithValue("@contactnam", Me.txtname.Text)
            cmd.Parameters.AddWithValue("@compname", Me.txtcompany.Text)
            cmd.Parameters.AddWithValue("@emailadd", Me.txtemail.Text)
            cmd.Parameters.AddWithValue("@phoneum", Me.txtpnumber.Text)
            cmd.Parameters.AddWithValue("@contactid", Me.lbcontactid.Text)

            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
        Finally
            con.Close()
        End Try
    End Sub
Member Avatar for Unhnd_Exception
cmd.CommandText = "update Contacts " & vbCrLf & _
                       "SET Contactname = @contactnam," & vbCrLf & _
                            "company = @compname," & vbCrLf & _
                            "emailaddress = @emailadd," & vbCrLf & _
                            "phonenumber = @phoneun" & vbCrLf & _
                       "where Contactid = @contactid"

thanks, this worked first time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.