Jump to content

Problem adding a record

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Shaddix

Shaddix

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
I'm writing a function to add a new record to my table "ServiceCenters" from my access database

but I have encountered a problem which I can't seem to find on my own (I'm pretty sure it's something stupid, but if I don't see it...)

    
Public Sub VoegToe(ByVal tmpServiceCenter As bsServiceCenter)
        Try
            Dim cb As New OleDbCommandBuilder(da)
            cb.QuotePrefix = "["
            cb.QuoteSuffix = "]"
            Dim drv As DataRowView = dvServiceCenters.AddNew

            drv.BeginEdit()

            With tmpServiceCenter
                drv("SCenterId") = .SCenterId
                drv("Adres") = .Adres
                drv("Postcode") = .Postcode
                drv("TelefoonNr") = .TelefoonNr
                drv("Werknemers") = .AantalWerknemers
            End With

            drv.EndEdit()

            da.Update(dsAutomaatVerhuur, "ServiceCenters")

            dsAutomaatVerhuur.Tables("ServiceCenters").Clear()

            da.Fill(dsAutomaatVerhuur, "ServiceCenters")
        Catch ex As Exception
            dsAutomaatVerhuur.Tables("ServiceCenters").Clear()
            da.Fill(dsAutomaatVerhuur, "ServiceCenters")
            Throw New System.Exception("dbServiceCenter - Sub VoegToe" & vbCrLf & ex.Message)
        End Try
    End Sub

most things are declared and initialised in my module
Module modAutomaatVerhuur
    Public dsAutomaatVerhuur As New DataSet
    Public cnAutomaatVerhuur As OleDbConnection
    Public da As OleDbDataAdapter
    Public frmServiceCentersMogelijk As Boolean = True
    Public frmAutomaatMogelijk As Boolean = True
    Public frmAutomaatHuurderMogelijk As Boolean = True

    Public Sub InitDatabase()
        Dim sDataBaseLocation As String = "C:\Users\Tim\Desktop\Examen ADO\Database.accdb"

        cnAutomaatVerhuur = New OleDbConnection
        cnAutomaatVerhuur.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & sDataBaseLocation
        VulAutomaten()
        VulServiceCenters()
        VulAutomaatHuurders()
    End Sub
    Public Sub VulAutomaten()
        Dim cm As New OleDbCommand("SELECT * FROM Automaten", cnAutomaatVerhuur)
        da = New OleDbDataAdapter(cm)
        da.Fill(dsAutomaatVerhuur, "Automaten")
    End Sub
    Public Sub VulServiceCenters()
        Dim cm As New OleDbCommand("SELECT * FROM ServiceCenters", cnAutomaatVerhuur)
        da = New OleDbDataAdapter(cm)
        da.Fill(dsAutomaatVerhuur, "ServiceCenters")
    End Sub
    Public Sub VulAutomaatHuurders()
        Dim cm As New OleDbCommand("SELECT * FROM AutomaatHuurders", cnAutomaatVerhuur)
        da = New OleDbDataAdapter(cm)
        da.Fill(dsAutomaatVerhuur, "AutomaatHuurders")
    End Sub
End Module

the error I get is:

Quote

missing the DataColumn 'ServiceCenter' in the DataTable 'ServiceCenters' for the SourceColumn 'ServiceCenter'


and my db looks like this:
ServiceCenters
----------------
SCenterId
Adres
Postcode
TelefoonNr
Werknemers


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I think you want to use SCenterID in your SQL instead of ServiceCenter.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog