E
Eric_Davison
Guest
my Insert code statement works correctly but, my update code gives me an error from beginning =" which is after the as String Like I said my insert statements works fine. The update statement the error is something to with the '&' here is the entire code. I am learning this code as I go the Insert I was able to watch video and it worked then I tried the Update and it is not working I am lost. Any help would be grateful thank you
Imports System.Data.SqlClient
Public Class CustomerForm
Dim connection As New SqlConnection("Server=desktop-9h1rijt;Database=Service;user=sa;Pwd=MidWest;")
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles addbttn.Click
Dim insertQuery As String = "INSERT INTO customer (firstname,lastname,address1,address2,city,zipcode,state,phone1,phone2,email)
VALUES('" & firstnametxbox.Text & "','" & lastnametxbox.Text & "','" & addresstxbx1.Text & "','" & address2txbx.Text & "','" & citytxbx.Text & "','" & ziptxbx.Text & "',
'" & statetxbx.Text & "','" & phone1txbx.Text & "','" & phone2txbx.Text & "','" & emailtxbx.Text & "')"
ExcuteQuery(insertQuery)
MessageBox.Show("Data Inserted")
End Sub
Public Sub ExcuteQuery(query As String)
Dim command As New SqlCommand(query, connection)
connection.Open()
command.ExecuteNonQuery()
connection.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim updateQuery As String = "Update Customer SET firstname = '" & firstnametxbox.Text & "', lastname = '" & lastnametxbox.Text & "',
phone1 ='" & phone1txbx.Text & "' , phone2 = '" & phone2txbx.Text & "', address1 = '" & addresstxbx1.Text & "',
address2 = '" & address2txbx.Text & "' , city = '" & citytxbx.Text & "' , state = '" & statetxbx.Text & "' ,
zipcode = '" & ziptxbx.Text & "' , email = '" & emailtxbx.Text & "' WHERE customerID(" & conttxbx & ")"
ExcuteQuery(updateQuery)
MessageBox.Show("Data Updated")
End Sub
Continue reading...
Imports System.Data.SqlClient
Public Class CustomerForm
Dim connection As New SqlConnection("Server=desktop-9h1rijt;Database=Service;user=sa;Pwd=MidWest;")
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles addbttn.Click
Dim insertQuery As String = "INSERT INTO customer (firstname,lastname,address1,address2,city,zipcode,state,phone1,phone2,email)
VALUES('" & firstnametxbox.Text & "','" & lastnametxbox.Text & "','" & addresstxbx1.Text & "','" & address2txbx.Text & "','" & citytxbx.Text & "','" & ziptxbx.Text & "',
'" & statetxbx.Text & "','" & phone1txbx.Text & "','" & phone2txbx.Text & "','" & emailtxbx.Text & "')"
ExcuteQuery(insertQuery)
MessageBox.Show("Data Inserted")
End Sub
Public Sub ExcuteQuery(query As String)
Dim command As New SqlCommand(query, connection)
connection.Open()
command.ExecuteNonQuery()
connection.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim updateQuery As String = "Update Customer SET firstname = '" & firstnametxbox.Text & "', lastname = '" & lastnametxbox.Text & "',
phone1 ='" & phone1txbx.Text & "' , phone2 = '" & phone2txbx.Text & "', address1 = '" & addresstxbx1.Text & "',
address2 = '" & address2txbx.Text & "' , city = '" & citytxbx.Text & "' , state = '" & statetxbx.Text & "' ,
zipcode = '" & ziptxbx.Text & "' , email = '" & emailtxbx.Text & "' WHERE customerID(" & conttxbx & ")"
ExcuteQuery(updateQuery)
MessageBox.Show("Data Updated")
End Sub
Continue reading...