Hi I'm getting the following exception from accessDa.Update(ds.Tables(0))


No value given for one or more required parameters

In the following code (marked in red).

Protected Sub DataTableCurrMonthForWorker(ByVal ccMifal, ByVal ccWorkerID, ByVal theYear, ByVal theMonth)
        Dim totInsert As Integer
        Dim currDay As Integer = 1
        Dim theDate As Date
        Dim ds As New DataSet("dsClockCard")
        Dim dt As New DataTable("ClockCard")
        Dim dc As DataColumn
        Dim dr As DataRow
        ds.Tables.Add(dt)
        dc = New DataColumn("Mifal", GetType(Integer), ccMifal)
        dt.Columns.Add(dc)
        dc = New DataColumn("WorkerID", GetType(Integer), ccWorkerID)
        dt.Columns.Add(dc)
        dc = New DataColumn("ccYear", GetType(Integer), theYear)
        dt.Columns.Add(dc)
        dc = New DataColumn("ccMonth", GetType(Integer), theMonth)
        dt.Columns.Add(dc)
        dc = New DataColumn("ccDay", GetType(Integer))
        dt.Columns.Add(dc)
        dc = New DataColumn("ccSubDay", GetType(Integer), 1)
        dt.Columns.Add(dc)
        dc = New DataColumn("ccDate", GetType(Date))
        dt.Columns.Add(dc)
        If IsDate(theMonth & "/" & 20 & "/" & theYear) Then
            While IsDate(theMonth & "/" & currDay & "/" & theYear)
                theDate = theMonth & "/" & currDay & "/" & theYear
                dr = dt.NewRow
                dr.BeginEdit()
                dr(4) = currDay
                dr(6) = theDate
                dt.Rows.Add(dr)
                dr.EndEdit()
                currDay = currDay + 1
            End While
        Else
            While IsDate(currDay & "/" & theMonth & "/" & theYear)
                theDate = theMonth & "/" & currDay & "/" & theYear
                dr = dt.NewRow
                dr.BeginEdit()
                dr(4) = currDay
                dr(6) = theDate
                dt.Rows.Add(dr)
                dr.EndEdit()
                currDay = currDay + 1
            End While
        End If
        DALayer.fnUpdateDataBaseFromDataSet(ds)
    End Sub

    Dim accessConn As New OleDbConnection
    Dim accessDa As OleDbDataAdapter
    Dim accessCmd As OleDbCommand

    Public Function fnUpdateDataBaseFromDataSet(ByVal ds As DataSet)
            Try
                If accessConn.State = ConnectionState.Open Then
                    accessDa = New OleDbDataAdapter(accessCmd)
                    accessCmd = New OleDbCommand("INSERT INTO  ClockCard ([Mifal], " & _
                                                [WorkerID], [ccYear], " & _
                                                "[ccMonth], [ccDay], " & _
                                                "[ccSubDay], [ccDate]) " & _
                                                "VALUES (@Mifal, @WorkerID, @ccYear, @ccMonth, " & _
                                                "@ccDay, @ccSubDay, @ccDate)", accessConn)
                    accessDa.InsertCommand = accessCmd
                     accessDa.Update(ds.Tables(0))                    accessConn.Close()
                    accessDa.Dispose()
                    Return True
          end if
            Catch ex As Exception
                Current.Response.Write("exception from fnUpdateDataBaseFromDataSet: " & ex.Message & "<br>")
            Finally
                If accessConn.State = ConnectionState.Open Then
                    accessConn.Close()
                    accessDa.Dispose()
                End If
            End Try

I've looped thru the ds dataset and all the columns have notNull values
I've checked the field names and number of columns are ok

Any Help appriciated

Thanks

Recommended Answers

All 2 Replies

Pls. check your Paramater values may have extra ", " (comma ). when SQL encounter any comma, it considers a new param. pls . try and let me know.

INSERT INTO  ClockCard ([Mifal], " & _
                                                [WorkerID], [ccYear], " & _
                                                "[ccMonth], [ccDay], " & _
                                                "[ccSubDay], [ccDate]) " & _
                                                "VALUES 
(@Mifal, @WorkerID, @ccYear, @ccMonth,  "@ccDay, @ccSubDay, @ccDate)", accessConn)

Hi Yousuf,
Thanks for your reply, I've checked and as far as I can see everything's ok (no extra ", ") although the code when I pasted it in got a bit skewed.
Any othere ideas ? I've been on this for days!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.