file access with VB.NET

  • Thread starter Thread starter Dave Cullen
  • Start date Start date
D

Dave Cullen

I'm really confused about how to use the .NET file and stream stuff. Can
someone please show me how to do this...

I have a text data file with semicolon delimited fields. I need to check
if the file exists, and if it does open the file and read the data
fields into local variables. Simple enough I'm sure, but I can't figure
out from MSDN what methods to use.

I will also need to write to the file (replacing the old fields).

Thanks.
 
Hi Dave,

This is a sample about a comma seperated file, however that can be in your
culture setting as it is with mine a semicolon.

You have to open a form, and drag a datagrid on that to show the sample.

I hope this helps?

Cor

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\Test1\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
DataGrid1.DataSource = ds.Tables(0)
End Sub
 
Back
Top