hi every one i am trying to save data from vb.net form in sql server 2008 below is the code which i am using but the only problem is . i am not getting any error instead the data which is being saved in sql server in my First Name , Last Name and Address fields is not the one i insert into textboxes, when i check the backend it shows me my field values as first name , last name and address.
Dim FirstName As String
Dim LastName As String
Dim Address As String
FirstName = txtFirstname.Text
LastName = txtLastname.Text
Address = txtAddress.Text
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = ("Data Source=SAAD-PC\SQLEXPRESS;Initial Catalog=photoshoot;Integrated Security=True")
con.Open()
cmd.Connection = con
cmd.CommandText = "INSERT INTO staff(FirstName, LastName,Address) VALUES(@p1,@p2,@p3)"
cmd.Parameters.AddWithValue("@p1", FirstName)
cmd.Parameters.AddWithValue("@p2", LastName)
cmd.Parameters.AddWithValue("@p3", Address)
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
con.Close()
End Try