0

Hi, I'm using Visual Basic Express 2008 (VB.NEt). I've created a project which
connect to a Microsoft Access Database (OLEDB) & displays the records using textboxes in the windows app.

I need to add a button which exports the database to a fixed length text file. Does anyone know the code I would use to do this?

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by sknake
0

Are you sure you want to do that? That sounds so 1980ish :)

Anyways you could just create a class the represents each table in the database and override the .ToString() method and create a static length string.

0

Yes i'm sure. Their is a program that will be using the text file, so the text file can't be modified while it's in use. So I need the code for exporting the file at the click of a button.

0

You can open a file that is in use -- you just have to do it a special way. Here is the C# code but you should be able to port it to VB.NET easily enough. The FileStream() overload lets you open a file readonly while another application has it open for read/write.

using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
      {
        using (StreamReader sr = new StreamReader(fs))
        {

          string line;
          int lineNumber = 0;
          while ((line = sr.ReadLine()) != null)
          {

If that stops you from having to write a fixed length file then you should be good to go, right? You can modify the above code to copy the file if its a database .mdb file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.