R
Rocky48
Guest
I what to INSERT data into the database from user input from 2 comboboxes and a textbox.
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Using cn As New SqlConnection With {.ConnectionString = "Data Source=DESKTOP-S7FRNAL\SQLEXPRESS;Initial Catalog=Verses_Find;Integrated Security=True"},
cmd As New SqlCommand
Dim Evt As Integer
Dim SEvt As Integer
Dim Verse As String
Evt = cboEvent.SelectedValue
SEvt = cboSEvent.SelectedValue
Verse = txtNewVerse.Text
cn.Open()
cmd.Connection = cn
cmd.CommandText = "INSERT INTO Verse (Event, Event_Sub, Verse) VALUES (@Evt, @SEvt,@Verse)"
Dim num = cmd.ExecuteNonQuery
MessageBox.Show("Number of Records Updated = " & num.ToString)
End Using
End Sub
The exception occurs when it tries to Execute the query.
Not sure that the num declaration is needed as I copied this from a form that I had torun an UPDATE query.
Any help would be appreciated.
TEH
Continue reading...
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Using cn As New SqlConnection With {.ConnectionString = "Data Source=DESKTOP-S7FRNAL\SQLEXPRESS;Initial Catalog=Verses_Find;Integrated Security=True"},
cmd As New SqlCommand
Dim Evt As Integer
Dim SEvt As Integer
Dim Verse As String
Evt = cboEvent.SelectedValue
SEvt = cboSEvent.SelectedValue
Verse = txtNewVerse.Text
cn.Open()
cmd.Connection = cn
cmd.CommandText = "INSERT INTO Verse (Event, Event_Sub, Verse) VALUES (@Evt, @SEvt,@Verse)"
Dim num = cmd.ExecuteNonQuery
MessageBox.Show("Number of Records Updated = " & num.ToString)
End Using
End Sub
The exception occurs when it tries to Execute the query.
Not sure that the num declaration is needed as I copied this from a form that I had torun an UPDATE query.
Any help would be appreciated.
TEH
Continue reading...