mmarkym
Member
- Joined
- Aug 20, 2005
- Messages
- 13
- Programming Experience
- 3-5
I have this in my button_click procedure. The syntax for the command text property is producing an error.
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Try
cn.ConnectionString = "integrated security=true;data source='mark\netsdk';persist security info=False;initial catalog=Northwind"
cn.Open()
cmd.Connection = cn
cmd.CommandText = "Insert into Login Username = @username, Password = @password, Fname = @fname, Lname = @lname"
cmd.Parameters.Add("@username", SqlDbType.VarChar, 20, "Username")
cmd.Parameters.Add("@password", SqlDbType.VarChar, 20, "Username")
cmd.Parameters.Add("@fname", SqlDbType.VarChar, 20, "Username")
cmd.Parameters.Add("@lname", SqlDbType.VarChar, 20, "Username")
cmd.Parameters.Item(0).Value = txtUserName.Text
cmd.Parameters.Item(1).Value = txtPassword.Text
cmd.Parameters.Item(2).Value = txtFname.Text
cmd.Parameters.Item(3).Value = txtLname.Text
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cn.Close()
End Try
End Sub
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Try
cn.ConnectionString = "integrated security=true;data source='mark\netsdk';persist security info=False;initial catalog=Northwind"
cn.Open()
cmd.Connection = cn
cmd.CommandText = "Insert into Login Username = @username, Password = @password, Fname = @fname, Lname = @lname"
cmd.Parameters.Add("@username", SqlDbType.VarChar, 20, "Username")
cmd.Parameters.Add("@password", SqlDbType.VarChar, 20, "Username")
cmd.Parameters.Add("@fname", SqlDbType.VarChar, 20, "Username")
cmd.Parameters.Add("@lname", SqlDbType.VarChar, 20, "Username")
cmd.Parameters.Item(0).Value = txtUserName.Text
cmd.Parameters.Item(1).Value = txtPassword.Text
cmd.Parameters.Item(2).Value = txtFname.Text
cmd.Parameters.Item(3).Value = txtLname.Text
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cn.Close()
End Try
End Sub