Public Function GetDataset() As Boolean Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\names.dbf;Extended Properties=dBASE IV;" Dim OPOCmdSelect As New System.Data.OleDb.OleDbCommand Dim OPOAdapter As New System.Data.OleDb.OleDbDataAdapter Dim OPOConnection As New System.Data.OleDb.OleDbConnection Dim Tmpdataset As New DataSet Dim iRecFound As Integer Dim StrSQL As Integer Dim dv As DataView OPOConnection.ConnectionString = ConnectionString Try If OPOConnection.State = ConnectionState.Closed Then OPOConnection.ConnectionString = ConnectionString OPOConnection.Open() End If StrSQL = "Select * from names" OPOCmdSelect.CommandText = StrSQL OPOCmdSelect.Connection = OPOConnection OPOAdapter.SelectCommand = OPOCmdSelect iRecFound = OPOAdapter.Fill(Tmpdataset, "names") '####### We fill in the grid ####### dv = Tmpdataset.DefaultViewManager.CreateDataView(Tmpdataset.Tables(0)) DataGrid1.DataSource = dv Catch e As Exception Return False End Try Return True End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionFunction GetDataset() 'Fichier names.dbf dans D:\ Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\;Extended Properties=dBASE IV;" Dim OPOCmdSelect As New System.Data.OleDb.OleDbCommand Dim OPOAdapter As New System.Data.OleDb.OleDbDataAdapter Dim OPOConnection As New System.Data.OleDb.OleDbConnection Dim ds As New DataSet Dim iRecFound As Integer Dim StrSQL As String Dim dv As DataView OPOConnection.ConnectionString = ConnectionString Try If OPOConnection.State = ConnectionState.Closed Then OPOConnection.ConnectionString = ConnectionString OPOConnection.Open() End If StrSQL = "Select * from names" OPOCmdSelect.CommandText = StrSQL OPOCmdSelect.Connection = OPOConnection OPOAdapter.SelectCommand = OPOCmdSelect iRecFound = OPOAdapter.Fill(ds, "names") '+------ We fill in the grid ------+ dv = ds.DefaultViewManager.CreateDataView(ds.Tables(0)) DataGrid1.DataSource = dv '+---------------------------------+ 'We close the connection OPOConnection.Close() Catch e As OleDbException TextBox1.Text = e.Message 'Je copie l'erreur dans une texbox End Try End Function