G
Guest
I am new to ADO.NET, but am experienced in ADO and VB 6.0.
I am writing some procedures for use with an Access database. The particular
procedure I am writing now is designed to create a new SQL command and update
the DataAdapter, then return the filled DataSet. However, I am getting the
error "The DataAdapter.SelectCommand property needs to be initialized." when
the command "odbSFB.GetUpdateCommand()" is run.
I have found that to fix this I need to put "odbSFB = New
OleDb.OleDbCommandBuilder(odaSFB)" before the line. But, I am not sure the
consequence of this. As I understand it this will create another instance of
the CommandBuilder, is this correct? I would think that all I need to do is
update the CommandBuilder with the new SQL command, but cant find how to do
this/
I have attached the code for this procedure below.
Any help, suggestions or questions appreciated.
Thank you.
Tippy.
Code:
Friend Function DBCreateDataSet(ByVal sSQLString As String, ByVal
sRecordSetName As String) As DataSet
' create new dataset and return
' set OleDBCommand to execute SQL commands
cmdSFB = New OleDb.OleDbCommand(sSQLString, odcSFB)
' set new data adapter with command
odaSFB = New OleDb.OleDbDataAdapter(cmdSFB)
' set command builder to automatically generate the SQL commands
' needed to update the database later
If odbSFB Is Nothing Then
odbSFB = New OleDb.OleDbCommandBuilder(odaSFB)
Else
' this is the line needed to avoid the error.
odbSFB = New OleDb.OleDbCommandBuilder(odaSFB)
End If
' you can call GetUpdateCommand explicitly to generate the Update
' command based on the current CommandText property value.
odbSFB.GetUpdateCommand()
' create new dataset
DBCreateDataSet = New DataSet
' fill dataset
odaSFB.Fill(DBCreateDataSet, sRecordSetName)
End Function
I am writing some procedures for use with an Access database. The particular
procedure I am writing now is designed to create a new SQL command and update
the DataAdapter, then return the filled DataSet. However, I am getting the
error "The DataAdapter.SelectCommand property needs to be initialized." when
the command "odbSFB.GetUpdateCommand()" is run.
I have found that to fix this I need to put "odbSFB = New
OleDb.OleDbCommandBuilder(odaSFB)" before the line. But, I am not sure the
consequence of this. As I understand it this will create another instance of
the CommandBuilder, is this correct? I would think that all I need to do is
update the CommandBuilder with the new SQL command, but cant find how to do
this/
I have attached the code for this procedure below.
Any help, suggestions or questions appreciated.
Thank you.
Tippy.
Code:
Friend Function DBCreateDataSet(ByVal sSQLString As String, ByVal
sRecordSetName As String) As DataSet
' create new dataset and return
' set OleDBCommand to execute SQL commands
cmdSFB = New OleDb.OleDbCommand(sSQLString, odcSFB)
' set new data adapter with command
odaSFB = New OleDb.OleDbDataAdapter(cmdSFB)
' set command builder to automatically generate the SQL commands
' needed to update the database later
If odbSFB Is Nothing Then
odbSFB = New OleDb.OleDbCommandBuilder(odaSFB)
Else
' this is the line needed to avoid the error.
odbSFB = New OleDb.OleDbCommandBuilder(odaSFB)
End If
' you can call GetUpdateCommand explicitly to generate the Update
' command based on the current CommandText property value.
odbSFB.GetUpdateCommand()
' create new dataset
DBCreateDataSet = New DataSet
' fill dataset
odaSFB.Fill(DBCreateDataSet, sRecordSetName)
End Function