473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Writing recordset to a text file

I'm fairly new to VB.Net. Anyway our office has a simple application written in VB6 thats produces a recordset from an Access database then writes the resulting recordset to a text file. They want it re-written in .Net. I can get the (DAO) recordset to be created correctly in >net but I can't figure out how to write it to a delimited text file using CommonDialog. Any help would be appreciated.

Thanks in advance.
ronhvb03
Apr 17 '07 #1
2 4215
shweta123
692 Expert 512MB
Hi,

Try this function,
Expand|Select|Wrap|Line Numbers
  1. Function Text_To_Datasetst(ByVal filePath As String) As DataSet 
  2.  Dim reader As StreamReader = New StreamReader(filePath) 
  3.  reader.BaseStream.Seek(0, SeekOrigin.Begin) 
  4.  Dim ds As DataSet = New DataSet 
  5.  Dim dt As DataTable = New DataTable 
  6.  ds.Tables.Add("SampleTable") 
  7.  While reader.Peek > -1 
  8.    Dim cnt As Integer = 0 
  9.    drow = dt.NewRow 
  10.    For Each strfields As String In reader.ReadLine.Split(delimiter) 
  11.      drow(cnt) = Convert.ToDouble(strfields.Trim) 
  12.      System.Math.Min(System.Threading.Interlocked.Increment(cnt),cnt-1) 
  13.    Next 
  14.    dt.Rows.Add(drow) 
  15.  End While 
  16.  Return ds 
  17. End Function
  18.  
Apr 17 '07 #2
Not sure but I think this code writes to a dataset or database. I'm trying to write a DAO recordset to a text file. In the VB 6 app it is laid out like this:
Expand|Select|Wrap|Line Numbers
  1. If RsRpt.RecordCount > 0 Then
  2.   CommonDialog1.Action = 2
  3.   strPath = CommonDialog1.FileName + ".txt"
  4.   ' MsgBox "Path = " & strPath
  5.   If OpList.Value = True Then
  6.   Open strPath For Output As #1
  7. '    Open strPath + "\" + strOutFile For Output As #1
  8.     OpenRecordsetOutput RsRpt
  9.     Message = "File " + strPath + " has " + Str(RsRpt.RecordCount) + " records"
  10.     MsgBox Message, vbOKOnly, "File Output info"
  11.   End If
  12.  
  13.  
  14. Sub OpenRecordsetOutput(rstOutput As Recordset)
  15.  With rstOutput
  16.  '  MsgBox "Writing list file now"
  17.   Print #1, "YEAR", "|"; "GSE", "|"; "MSA", "|"; "MSA NAME", "|"; "STATE CODE", "|"; "STATE NAME", "|"; _
  18.             "COUNTY CODE", "|"; "COUNTY NAME", "|"; _
  19.             "TRACT", "|"; "TRACT PCT RATIO", "|"; "MINORITY PCT", "|"; _
  20.             "SERVE IND", "|"; "BUYER TYPE", "|"; "ETHNIC GRP", "|"; _
  21.             "GENDER", "|"; "BO RATIO", "|"; "# OF LOANS"
  22.   Do While Not .EOF
  23.  
  24.   Print #1, .Fields(0), "|"; .Fields(1), "|"; .Fields(2), "|"; .Fields(3), "|"; _
  25.   .Fields(4), "|"; .Fields(5), "|"; .Fields(6), "|"; .Fields(7), "|"; _
  26.   .Fields(8), "|"; .Fields(9), "|"; .Fields(10), "|"; .Fields(11), "|"; _
  27.   .Fields(12), "|"; .Fields(13), "|"; .Fields(14), "|"; .Fields(15), "|"; .Fields(16)
  28.  
  29.   .MoveNext
  30.  Loop
  31.  End With
  32. 'MsgBox "File complete"
  33. End Sub
  34.  
Apr 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: va | last post by:
I am trying to create recordset from a text file. The text file contains header and records. The text file is tab delimited. I am using the following statement to create the recordset Call...
2
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It...
14
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It...
6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
5
by: Wendy | last post by:
Hi I'm trying to import the contents of a text file which is basically letters in to a table to add more data to them. The original file comes from the mainframe. I'm tring to copy the...
1
by: Billy | last post by:
Hi All, I'm attempting to use the MapNetworkDrive <snippedbelow from entire code below with very poor performance results. Basically, I have very small 73kb text files that are rewritten daily...
7
by: tdr | last post by:
I need to compare table 1 to table 2 and if the row/recordset in table 1 is different from table 2, write the entire row/recordset from table 1 to table 3. I can read an entire row/recordset ...
1
by: anniefs | last post by:
hi help me i m so much stuck int he code and i have no time .... i used ASP VBscipt and javascript functions with MS database javascript function add records in MS DB by using ASP vbscript...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.