Results 1 to 6 of 6

Thread: DataTableAdapter.Fill Error: Command is missing required clause

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2014
    Posts
    5

    DataTableAdapter.Fill Error: Command is missing required clause

    I am trying to read three dBase IV tables. The code works fine with two of the tables but not the third. The exception message is not particularly informative as all three are identical except for names.The problem is near the end on file csInd.dbf. Since the required extension for connecting to dBase files, I had to check for that file extension and copy files if necessary. That works fine. Here is the code:
    Code:
      Private Sub BuildDB()
            Try
                ' Checking for existence and naming of required data tables
                ' Family Data Table -- This will form dataset and parent table
                If Not (My.Computer.FileSystem.FileExists(UserFolder + "csFamily.dbf")) Then
                    If My.Computer.FileSystem.FileExists(UserFolder + "csfamily.udb") Then
                        My.Computer.FileSystem.CopyFile(UserFolder + "csfamily.udb", UserFolder + "csfamily.dbf")
                    Else
                        gMsg = "Neither file " + UserFolder + "csFamily.udb nor file " + UserFolder + "csFamily.dbf was found."
                        MsgBox(gMsg, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
                        btnEnd.PerformClick()
                    End If
                End If
    
                'Individual DataTable csInd.dbf  This is child table
                If Not (My.Computer.FileSystem.FileExists(UserFolder + "csInd.dbf")) Then
                    If (My.Computer.FileSystem.FileExists(UserFolder + "csInd.udb")) Then
                        My.Computer.FileSystem.CopyFile(UserFolder + "csInd.udb", UserFolder + "csInd.dbf")
                    Else
                        gMsg = "Neither file " + UserFolder + "csInd.udb nor file " + UserFolder + "csInd.dbf was found."
                        MsgBox(gMsg, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
                        btnEnd.PerformClick()
                    End If
                End If
                'Using cdFamily to build dsFamily dataset and dtFamily datatable
                    Dim csFamily As String = ""
                    csFamily = "Provider=vfpoledb;Data Source=" & UserFolder & "csFamily.dbf;Extended Properties=dBASE IV;User ID=Admin;Password=;"
                    Dim dcFamily As OleDb.OleDbConnection = New OleDb.OleDbConnection(csFamily)
                    Dim cmdFamily As New OleDb.OleDbCommand("SELECT FAMILY_ID,FAM_NAME, ADDR1,ADDR2, CITY,STATE,ZIP,H_PHONE,GROUP_NAME,HEAD,HEAD_ID,SPOUSE,SPOUSE_ID,UDF1,UDF2 FROM csFamily ORDER BY GROUP_NAME", dcFamily)
                    Dim daFamily As New OleDb.OleDbDataAdapter
                    Dim dsFamily As New DataSet("dsFamily")
                Dim bsFamily As BindingSource = New BindingSource
                'Checking for Photo data table. Will incorporate photo path in dtFamily
                If Not (My.Computer.FileSystem.FileExists(UserFolder + "csphoto.dbf")) Then
                    If My.Computer.FileSystem.FileExists(UserFolder + "csphoto.udb") Then
                        My.Computer.FileSystem.CopyFile(UserFolder + "csphoto.udb", UserFolder + "csphoto.dbf")
                    Else
                        gMsg = "Neither file " + UserFolder + "csphoto.udb nor file " + UserFolder + "csphoto.dbf was found."
                        MsgBox(gMsg, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
                        btnEnd.PerformClick()
                    End If
                End If
    
                Dim csPhoto As String = ""
                    csPhoto = "Provider=vfpoledb;Data Source=" & UserFolder & "csphoto.udb;Extended PropELerties=dBASE IV;User ID=Admin;Password=;"
                    Dim dcPhoto As OleDb.OleDbConnection = New OleDb.OleDbConnection(csPhoto)
                    Dim cmdPhoto As New OleDb.OleDbCommand("SELECT PHOTO_ID, FILE_LIB FROM csPhoto.udb ORDER BY PHOTO_ID", dcPhoto)
                    Dim cmdPhotoString As String = cmdPhoto.CommandText
                    Dim daPhoto As New OleDb.OleDbDataAdapter
                    Dim dsPhoto As New DataSet("dsPhoto")
                    Dim dtPhoto As New DataTable
                    Dim bsPhoto As BindingSource = New BindingSource
                'Finally building dsFamily and getting the photo path
                dcFamily.Open()
                    daFamily.SelectCommand = cmdFamily
                'daFamily.Fill(dtFamily)
                    daFamily.Fill(dsFamily, "dtFamily")
                    bsFamily.DataSource = dtFamily
                dcPhoto.Open()
                    daPhoto.SelectCommand = cmdPhoto
                ' daPhoto.Fill(dtPhoto)
                    daPhoto.Fill(dsPhoto, "dsPhoto")
                    bsPhoto.DataSource = dtPhoto
                    Dim colcount As Integer = dtFamily.Columns.Count
                    dtFamily.Columns.Add("PhotoLocation")
                    Dim FamID As String = ""
                Dim RowCount As Integer = dtFamily.Rows.Count
                'Getting photo path and inserting it into dtFamily 
                    For I = 0 To RowCount - 1
                        FamID = dtFamily.Rows(I).Item("Family_ID")
                        Try
                            Dim r() As DataRow = dtPhoto.Select("Photo_ID = " + FamID)
                            dtFamily.Rows(I).Item(colcount) = r(0).Item(1)
                        Catch ex2 As Exception
                        End Try
                    Next
                    With dgvFamily
                        .DataSource = dtFamily
                        .Show()
                    End With
                    nbrFamilies = dtFamily.Rows.Count
                    'nbrFamilies = dgvFamily.RowCount
                'MsgBox("Number of Family Records: " + nbrFamilies.ToString)
                'Working on csInd to get datatable dtInd
                Dim csInd As String = "Provider=vfpoledb;Data Source=" & UserFolder & "csind.dbf;Extended Properties=dBASE IV;User ID=Admin;Password=;"
                Dim dtInd As New DataTable
                ' Dim dsInd As New DataSet("dsInd")
                Dim dcInd As OleDb.OleDbConnection = New OleDb.OleDbConnection(csInd)
                Dim cmdInd As New OleDb.OleDbCommand("SELECT Ind_ID, FAMILY_ID, FIRST_NAME, LAST_NAME,PREFERNAME,C_PHONE,EMAIL1,EMAIL2", dcInd)
                Dim cmdIndString As String = cmdInd.CommandText
                Dim daInd As New OleDb.OleDbDataAdapter
                daInd.SelectCommand = cmdInd
                Dim bsInd As BindingSource = New BindingSource
                dcInd.Open()
                daInd.Fill(dtInd)
                bsInd.DataSource = dtInd
                dsFamily.Tables.Add(dtInd)
                dsFamily.Relations.Add("FamilyMembers", dsFamily.Tables("dtFamily").Columns("FAMILY_ID"), dsFamily.Tables("dtInd").Columns("FAMILY_ID"))
                ' WordPrintDirectory()
                SingleColumnWordPrint()
            Catch ex As Exception
                gMsg = "The following error occurred building the database:" + vbCrLf + ex.Message.ToString + vbCrLf
                MsgBox(gMsg, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
                btnEnd.PerformClick()
            End Try
        End Sub
    Last edited by Shaggy Hiker; Mar 12th, 2021 at 01:05 PM. Reason: Added CODE tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width