Code:
Public Sub InsertIndividualOnly(ByRef source As DEST_IndClient)
Dim result As DialogResult = MessageBox.Show("Verify your submission before committing!", "Verify", MessageBoxButtons.OKCancel)
If result = DialogResult.OK Then
Try
Query = "INSERT INTO DEST_clientIndividuals (IndividualFirst_name, IndividualLast_name, IndividualAddress1, IndividualAddress2, IndividualCity, StateID,IndividualZipcode, IndividualHome_phone, IndividualWork_phone, IndividualWork_phone_extension, IndividualFax_phone, IndividualCell_phone, IndividualEmail) VALUES (@fname, @lname, @address1, @address2, @city, @state, @zipcode, @hphone, @wphone, @wphoneext, @fphone, @cphone, @email)"
Connection.Open()
Command = New OleDbCommand(Query, Connection)
With Command
.Parameters.AddWithValue("@fname", source.firstname)
.Parameters.AddWithValue("@lname", source.lastname)
.Parameters.AddWithValue("@address1", source.address1)
.Parameters.AddWithValue("@address2", source.address2)
.Parameters.AddWithValue("@city", source.city)
.Parameters.AddWithValue("@state", source.state)
.Parameters.AddWithValue("@zipcode", source.zipcode)
.Parameters.AddWithValue("@hphone", source.homephone)
.Parameters.AddWithValue("@wphone", source.workphone)
.Parameters.AddWithValue("@wphoneext", source.workphoneext)
.Parameters.AddWithValue("@fphone", source.faxphone)
.Parameters.AddWithValue("@cphone", source.cellphone)
.Parameters.AddWithValue("@email", source.email)
End With
Command.ExecuteNonQuery()
Connection.Close()
Catch ex As OleDb.OleDbException
frmMain.tb_statusOutput.Text = ex.Message
End Try
Try
Query = "SELECT @@IDENTITY FROM clientIndividuals"
Connection.Open()
Command = New OleDbCommand(Query, Connection)
Dim newID As Integer = Command.ExecuteScalar()
MsgBox(newID)
'Command.ExecuteNonQuery()
Connection.Close()
Catch ex As OleDb.OleDbException
frmMain.tb_statusOutput.Text = ex.Message
End Try
End If
End Sub
If I set a breakpoint at the "Command = New OleDbCommand(Query, Connection)" line and setp through each line I get an error at the line "Command.ExecuteNonQuery()". It says, "Parameter @address2 has no default value." The order of the parameters relative to how it is in the actual database is exact. What could be causing this?