Results 1 to 3 of 3

Thread: Saving a new row to the database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Posts
    17

    Unhappy Saving a new row to the database

    The following prodedure should save a new row to the database.

    I can't see what the error is, but when I create the command builder, the complier does not like dbsupport.

    What have I done wrong

    Dim NewRow As System.Data.DataRow
    Dim dsadapter As OleDbDataAdapter
    Dim dr As DataRow

    dr = dssupport.Tables("Supportcall").NewRow()

    dr("ID") = txtcallnumber.Text
    dr("Customer") = cmbcustomer.Text
    dr("Description") = txtcalldescription
    dr("Contact") = txtcallcontact.Text

    'Get connection string
    strconn = "Provider=Microsoft.jet.oledb.4.0;" & "Data Source =P:\Support Calls\mosaic.mdb"

    'Build SQL string
    insertsql = "INSERT INTO Supportcall(ID, Customer, Description, Contact)" & " VALUES(?,?,?,?)"

    'Create new data adpater
    dbsupport = New OleDbDataAdapter(insertSQL, strconn)

    'Create command builder for adapter
    cmbbuild = New OleDbDataAdapter(dbsupport)

    'Get Insert command object
    dbsupport.InsertCommand = cmbbuild.GetInsertCommand()

    'Submit insert statement through adpater
    dbsupport.Update(dssupport, "Supportcall")

    'Tell data set changes are complete
    dssupport.AcceptChanges()

  2. #2
    Addicted Member
    Join Date
    Mar 2001
    Location
    Devon, UK
    Posts
    181
    You are referencing dssupport before you are creating an instance of it - which you do later in your code. Also you need to put your code in a try-catch-end try block. This will enable you to debug your code more efficiently and gives you error messages in your autos window
    Wind and waves resolves all problems.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Posts
    17

    Where do I do that then?

    How should I reorganise the code then

Posting Permissions

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



Click Here to Expand Forum to Full Width