Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Connect to CSV Data from PowerBuilder
This article demonstrates how to access CSV data from Appeon PowerBuilder using the CData ADO.NET Provider for CSV.
This article demonstrates using the CData ADO.NET Provider for CSV in PowerBuilder, showcasing the ease of use and compatibility of these standards-based controls across various platforms and development technologies that support Microsoft .NET, including Appeon PowerBuilder.
This article shows how to create a basic PowerBuilder application that uses the CData ADO.NET Provider for CSV to retrieve data.
- In a new WPF Window Application solution, add all the Visual Controls needed for the connection properties. Below is a typical connection string:
DataSource=MyCSVFilesFolder;
The DataSource property must be set to a valid local folder name.
Also, specify the IncludeFiles property to work with text files having extensions that differ from .csv, .tab, or .txt. Specify multiple file extensions in a comma-separated list. You can also set Extended Properties compatible with the Microsoft Jet OLE DB 4.0 driver. Alternatively, you can provide the format of text files in a Schema.ini file.
Set UseRowNumbers to true if you are deleting or updating in CSV. This will create a new column with the name RowNumber which will be used as key for that table.
- Add the DataGrid control from the .NET controls.
-
Configure the columns of the DataGrid control. Below are several columns from the Account table:
<DataGrid AutoGenerateColumns="False" Margin="13,249,12,14" Name="datagrid1" TabIndex="70" ItemsSource="{Binding}"> <DataGrid.Columns> <DataGridTextColumn x:Name="idColumn" Binding="{Binding Path=Id}" Header="Id" Width="SizeToHeader" /> <DataGridTextColumn x:Name="nameColumn" Binding="{Binding Path=City}" Header="City" Width="SizeToHeader" /> ... </DataGrid.Columns> </DataGrid>
- Add a reference to the CData ADO.NET Provider for CSV assembly.
Connect the DataGrid
Once the visual elements have been configured, you can use standard ADO.NET objects like Connection, Command, and DataAdapter to populate a DataTable with the results of an SQL query:
System.Data.CData.CSV.CSVConnection conn
conn = create System.Data.CData.CSV.CSVConnection(connectionString)
System.Data.CData.CSV.CSVCommand comm
comm = create System.Data.CData.CSV.CSVCommand(command, conn)
System.Data.DataTable table
table = create System.Data.DataTable
System.Data.CData.CSV.CSVDataAdapter dataAdapter
dataAdapter = create System.Data.CData.CSV.CSVDataAdapter(comm)
dataAdapter.Fill(table)
datagrid1.ItemsSource=table.DefaultView
The code above can be used to bind data from the specified query to the DataGrid.