Question OleDBCommandBuilder issue

galexan

New member
Joined
Aug 26, 2008
Messages
2
Programming Experience
Beginner
So I am trying to read a text file containing a data dump we get from a vendor. I need to read it into a Visual FoxPro Free Table. I have the table created with the correct structure to it, but I am having a problem getting OleDBCommand Builder to generate the insert command. I'm pretty sure I am missing a step somewhere but I have been looking at the code too long, and I'm really not that familiar using OLE Db with FoxPro. So I could really use a fresh set of eyes to help.
Here is my code (VS2008 + .NET 3.0)


VB.NET:
Expand Collapse Copy
Dim lcSQL As String = "select * from melbaset.dbf"
        Dim oConn = New OleDbConnection("Provider=vfpoledb.1; Data Source=" + strResultPath + "; connection Timeout = 3600")
        Dim oAdapter As OleDbDataAdapter = New OleDbDataAdapter
        Dim omyCommand As OleDbCommand = New OleDbCommand(lcSQL, oConn)
        Dim oAda As OleDbDataAdapter = New OleDbDataAdapter(omyCommand)
        Dim oCmb As New OleDbCommandBuilder(oAdapter)
        Dim dst As DataSet = New DataSet
        Dim intRows As Integer
        oAda.Fill(dst, "Melbaset")
        Dim intNum As Integer = 0
        While strLine <> Nothing And strLine.Length = 650
            If intNum = 5000 Then
                omyCommand.CommandTimeout = 3600
                oAdapter.SelectCommand = omyCommand
                '********************************************
                'This is where I'm Having my problem.
                'I get the following error:
                '"Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information."
                '********************************************
                oAdapter.InsertCommand = oCmb.GetInsertCommand
                intRows = oAdapter.Update(dst, dst.Tables(0).TableName)
                dst = Nothing
                dst = New DataSet
                oAda.Fill(dst, "Melbaset")
                intNum = 0
            End If
            Dim drow As DataRow = dst.Tables(0).NewRow()
            'Code break the line up into the correct fields.
            dst.Tables(0).Rows.Add(drow)
            intNum = intNum + 1
            strLine = objStreamReader.ReadLine
        End While
        If intNum > 0 Then
            omyCommand = New OleDbCommand(lcSQL, oConn)
            omyCommand.CommandTimeout = 3600
            oAdapter = New OleDbDataAdapter
            oAdapter.SelectCommand = omyCommand
            Dim oCmb2 As New OleDbCommandBuilder(oAdapter)
            oAdapter.InsertCommand = oCmb2.GetInsertCommand
            intRows = oAdapter.Update(dst, dst.Tables(0).TableName)
            dst = Nothing
        End If
        objStreamReader.Close()
Any help would be appreciated!
 
Actually I figured it out. I had an old OLE driver for FoxPro that didn't support dynamic generation of the insert command. Once I installed the new OLE driver everything worked fine... First time I have actually had any luck searching MS KB Articles...
 
Back
Top