|
-
Jul 31st, 2012, 04:39 PM
#1
Thread Starter
Addicted Member
Help with Access (OleDb) and VB.net
I'm trying to insert a record and then get the new ID generated for that new record. Here's my code.
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?
-
Jul 31st, 2012, 04:54 PM
#2
Re: Help with Access (OleDb) and VB.net
I never fill in Address2 on any form I fill out. Is there data? Does there need to be? It kind of sounds like the field can't be Null, yet you are supplying nothing.
My usual boring signature: Nothing
 
-
Aug 1st, 2012, 08:17 AM
#3
Thread Starter
Addicted Member
Re: Help with Access (OleDb) and VB.net
Address 1 and 2 is for physical and mailing addresses of a company profile. I just checked the fields and both address 1 and 2 are able to hold null.
-
Aug 1st, 2012, 08:42 AM
#4
Re: Help with Access (OleDb) and VB.net
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|