Results 1 to 4 of 4

Thread: Help with Access (OleDb) and VB.net

  1. #1
    Addicted Member
    Join Date
    Jan 10
    Location
    San Marcos, TX
    Posts
    177

    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?

  2. #2
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,410

    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

  3. #3
    Addicted Member
    Join Date
    Jan 10
    Location
    San Marcos, TX
    Posts
    177

    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.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,555

    Re: Help with Access (OleDb) and VB.net

    Error says exactly what it means. http://office.microsoft.com/en-us/ac...010096451.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •