locked
Dataset with Insert Error: Column name or number of supplied values does not match table definition. RRS feed

  • Question

  • Hi all,

    What can cause this error when updating dataset to database?
     Insert Error: Column name or number of supplied values does not match table definition.

    I have 2 dataset & i can update the first dataset. the second dataset give me the error. What could be wrong?



    Query Function:
        Public Function GetDataSQL(ByVal TableName As String, ByVal sSQL As String) As DataSet
            Dim ds As New DataSet(TableName)
            Dim cmd As SqlCommand = New SqlCommand
            Dim conn As SqlConnection = New SqlConnection(connString)
            Dim da As SqlDataAdapter = New SqlDataAdapter '(sSQL, conn)
            Try
                da.SelectCommand = New SqlCommand(sSQL, conn)
                conn.Open()
                da.FillSchema(ds, SchemaType.Source, TableName)
                da.Fill(ds, TableName)
                conn.Close()
                Return ds
            Catch ex As Exception
                Throw ex
            Finally
                conn.Close()
                da.Dispose()
                ds.Dispose()
            End Try

    =============
    Update function:
        Public Function UpdateData_DS(ByVal DS As DataSet, ByVal TableName As String, _
                                        Optional ByVal Field As String = "*") As Boolean
            Dim sSQL As String = "SELECT " & Field & " FROM " & TableName
            Dim conn As New SqlConnection(connString)
            Dim da As New SqlDataAdapter(sSQL, conn)
            Try
                conn.Open()
                Dim objCommandBuilder As New SqlCommandBuilder(da)
                da.Update(DS.Tables(0).GetChanges)
                conn.Close()
            Catch exSQL As SqlException
                Throw exSQL
            Finally
                conn.Close()
                da.Dispose()
            End Try
        End Function
    Thursday, July 12, 2007 10:22 AM

Answers

  • uh, found the problem.

    its bcoz of corrupted database table.

    thanks...
    Friday, July 13, 2007 8:01 AM

All replies

  • Error means that provider does not see some mapping between parameters in a SQL statement that inserts or updates database and column names from the dataset. Another potential issue is if some of the column names or table name is a reserved word, like DATE, TIME etc or contains space character(s). In this case all the names should be wrapped into square brackets

    Thursday, July 12, 2007 10:36 AM
  • An addition to your code, which is not related to the error. Do not catch and re-throw same exception. It is very expensive from the performance point of view and bad practice, where exception stack information could be lost. If you are not going to re-throw your own, custom exception, then just remove catch part from the code completely and just leave Ty... Finally

    Thursday, July 12, 2007 10:38 AM
  • uh, found the problem.

    its bcoz of corrupted database table.

    thanks...
    Friday, July 13, 2007 8:01 AM