I need to select one of each version in the data while keeping all the columns as well. Then I need to export the one record of each version to a new .dbf file. The issue I am having is with the SQL statement. I have tried different iterations of the SQL Statement but nothing appears to work. The code I have provided selects one of each version but does not include the rest of the columns. Here is my code:
Code:Dim ofd As New OpenFileDialog With ofd .Filter = "DBASE File (*.dbf)|*.dbf" .Multiselect = False .CheckFileExists = True End With If ofd.ShowDialog() = DialogResult.OK Then Dim fi As New IO.FileInfo(ofd.FileName) Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBase IV;Data Source='" _ & fi.DirectoryName & "'") Dim TableName As String = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length) Dim cmd As New OleDb.OleDbCommand(TableName, cn) cmd.CommandType = CommandType.TableDirect cn.Open() Dim rdr As OleDb.OleDbDataReader = cmd.ExecuteReader dt.Load(rdr) SelectField.ShowDialog() Dim dBaseConnection As New System.Data.OleDb.OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;” & “Data Source=” & path & “;” & “Extended Properties=dBase IV”) dBaseConnection.Open() Dim SQLCreateCommand As String Dim sql2 = "SELECT DISTINCT " & Field1 & " INTO NewTable " & " from " & TableName Dim dBaseCommand As New System.Data.OleDb.OleDbCommand(sql2, dBaseConnection) dBaseCommand.ExecuteNonQuery() dBaseConnection.Close() cn.Close() cn.Dispose() End If




Reply With Quote
