Accessing Text File Databases in ADO.NET


This article has been excerpted from book "A Programmer's Guide to ADO.NET in C#".

To test database connectivity, you can export the Employees table of the Northwind database using the File > Export option of Access 2000. In this section, I'll export a table to a text file, and I'll show you how to use it using the ODBC data adapter.

Exporting an Access Table to a Text File

You can export an Access database table to a text file using the Export option. As you can see from figure 11-22, I selected the Employees table and chose file > Export.

Note: You can also select the Export option by right-clicking on the table.

Figure-11.22.gif

Figure 11-22: Exporting the employees table of Northwind.mdb

The next dialog box lets you pick a path and filename you want to export. There are many export options are available. As you can see from figure 11-23, I selected the Text files option, left the exported filename as Employees, and saved the file to the C:\root directory. 

Figure-11.23.gif

Figure 11-23: Selecting a path of exporting file

Now, the Export Text Wizard lets you define the format of the text file. A dialog box lets you select either delimited or fixed width (see Figure 11-24).

Figure-11.24.gif

Figure 11-24: Export Text Wizard options

You can also select the Advanced option to set more options (see Figure 11-25).

Figure-11.25.jpg

Figure 11-25: The Advanced option of Export Text Wizard

The next screen lets you pick the delimiter including comma, tab, semicolon, space, and others. I left the Comma option checked (see Figure 11-26).

Figure-11.26.gif

Figure 11-26: Delimiter options of Export Text Wizard

I also checked the Include Field Names on first Row check box. This option adds the first row of the text file as field names. 

The last page asks you the filename (see Figure 11-27).

Figure-11.27.jpg

Figure 11-27: Filename page of the Export Text Wizard

Now click the finish button. When the wizard is done exporting, you'll see a message saying the export is finished. Click OK and close Access. 

Now view C:\Employees.txt (see figure 11-28).

Figure-11.28.gif

Figure 11-28: Exported Employees.txt file from Northwind.mdb

Conclusion

Hope this article would have helped you in understanding Accessing Text File Databases in ADO.NET. See my other articles on the website on ADO.NET.

adobook.jpg
This essential guide to Microsoft's ADO.NET overviews C#, then leads you toward deeper understanding of ADO.NET.

Up Next
    Ebook Download
    View all
    Learn
    View all