I get error 'The dataadapter,selectcommand property needs to be initialized' when this code hits the line that sets the dataadapter.deletecommand. Any ideas what is wrong? The dataset going into this function is not a custom dataset.
Public Overrides Function SaveDataSet(ByVal ds As DataSet) As Integer
Dim DataAdapter As SqlDataAdapter
If TypeOf ds Is CDataSet Then
'/ If this is a custom DataSet, get a reference to the
'/ DataSet's data adapter and store it in the DataAdapter variable
Dim dsSql As CDataSet = CType(ds, CDataSet)
DataAdapter = CType(dsSql.DataAdapter, SqlDataAdapter)
Else
'/ If this is NOT a Custom DataSet, create a new Data Adapter
DataAdapter = New SqlDataAdapter()
End If
Dim CommandBuilder As New SqlCommandBuilder(DataAdapter)
DataAdapter.DeleteCommand = CommandBuilder.GetDeleteCommand()
DataAdapter.UpdateCommand = CommandBuilder.GetUpdateCommand()
DataAdapter.InsertCommand = CommandBuilder.GetInsertCommand()
' Update the data in the DataSet
Dim RowsUpdated As Integer = DataAdapter.Update(ds, ds.Tables(0).ToString())
Return RowsUpdated
End Function 'SaveDataSet
Public Overrides Function SaveDataSet(ByVal ds As DataSet) As Integer
Dim DataAdapter As SqlDataAdapter
If TypeOf ds Is CDataSet Then
'/ If this is a custom DataSet, get a reference to the
'/ DataSet's data adapter and store it in the DataAdapter variable
Dim dsSql As CDataSet = CType(ds, CDataSet)
DataAdapter = CType(dsSql.DataAdapter, SqlDataAdapter)
Else
'/ If this is NOT a Custom DataSet, create a new Data Adapter
DataAdapter = New SqlDataAdapter()
End If
Dim CommandBuilder As New SqlCommandBuilder(DataAdapter)
DataAdapter.DeleteCommand = CommandBuilder.GetDeleteCommand()
DataAdapter.UpdateCommand = CommandBuilder.GetUpdateCommand()
DataAdapter.InsertCommand = CommandBuilder.GetInsertCommand()
' Update the data in the DataSet
Dim RowsUpdated As Integer = DataAdapter.Update(ds, ds.Tables(0).ToString())
Return RowsUpdated
End Function 'SaveDataSet