I am having huge problems with my code.
I am trying to insert 1,2,3,4,5 for testing purposes into my SQL server table. It is not working and I am pulling my hair out trying to figure it out!!!!
HELPPPPPPPPPPPP!!!!!!!!!
Here is my code:
I am trying to insert 1,2,3,4,5 for testing purposes into my SQL server table. It is not working and I am pulling my hair out trying to figure it out!!!!
HELPPPPPPPPPPPP!!!!!!!!!
Here is my code:
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connectionString As String = "uid=xxxxx;pwd=xxxxx;data source=LAPTOP\SQLEXPRESS;initial catalog=CheckWeigher"
Dim connection As New SqlConnection(connectionString)
connection.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter
' Create the InsertCommand.
'Dim command = New SqlCommand("INSERT INTO Users (UserID, FirstName, LastName, Title, Password) " & "VALUES(1, 2, 3, 4, 5)", connection)
Dim command = New SqlCommand("INSERT INTO Users (UserID, FirstName, LastName, Title, Password) " & "VALUES(@UserID, @FirstName, @LastName, @Title, @Password)", connection)
' Add the parameters for the InsertCommand.
command.Parameters.Add("@UserID", SqlDbType.NVarChar, 255, TextBox2.Text)
command.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50, TextBox3.Text)
command.Parameters.Add("@LastName", SqlDbType.NVarChar, 50, TextBox4.Text)
command.Parameters.Add("@Title", SqlDbType.NVarChar, 50, TextBox5.Text)
command.Parameters.Add("@Password", SqlDbType.NVarChar, 50, TextBox10.Text)
adapter.InsertCommand = command
End Sub
Last edited by a moderator: