Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TransferText method in vb.net???

Status
Not open for further replies.

jeffmoore

Programmer
Aug 29, 2003
301
US
I'm converting a VBA program to VB.net. The program needs to import a csv file to my sql database. In access I was using the following command:

DoCmd.TransferText acImportDelim, "My_import_spec", _
"tbl_scan_data", "C:\MyDataFile.csv"

Q: How do I acomplish this in VB.net. Is there a way to use Access's language within VB.net?

Note: I have installed the MS office tools that comes with VB.net.

TIA
Jeff
 
Question continued.....

Would it help to add a reference to "Microsoft Access 11.0 Object Library" in my project???

If I do that, How do I get the VBA code to work???

Note: this is my first VB.net program.... Am I in over my head ???

;-)
 
I would look at streamreader and streamwriter if I was you and forget about access. Either you make the conversion or you don't. Don't try to make shortcuts, you'll be sorry in the end, if you ever get to the end.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Another way to connect to csv files is to use the Microsoft Text Driver. e.g.
Code:
        Dim MyConnection As System.Data.Odbc.OdbcConnection
        Dim MyDataTable As New DataTable
        Dim MyDataAdaptor As System.Data.Odbc.OdbcDataAdapter
        Dim strMyConnection, strSavedFolder, strFilename As String
        strSavedFolder = "c:\inetpub\[URL unfurl="true"]wwwroot\"[/URL]
        strFilename = "test.csv"
        strMyConnection = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & strSavedFolder & ";"
        MyConnection = New Odbc.OdbcConnection(strMyConnection)
        MyDataAdaptor = New System.data.Odbc.OdbcDataAdapter("select * from [" + strFilename + "]", MyConnection)
        MyDataAdaptor.Fill(MyDataTable)
        DataGrid1.DataSource = MyDataTable
        DataGrid1.DataBind()
but like chrissie says, forget about the VBA application as any attempts to convert it will just hinder you. Think of it as an entirely new project and build it from scratch - you'll be much happier with the final result.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
okay I'll dump the access refs and give the code above a shot ...
Thanks ..... I'm sure you'll be hearing form me again :)
Jeff
 
c8cmsm.... there is an error in the last line of code....

TIA
Jeff
 
ca8msm is a asp.net specialist and forgets that you don't need the databind in windows forms.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Oops - Thanks chrissie!

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
thanks chrissie1 and ca8msm .... I'll give the code a shot on monday...
 
okay the code works great ... except for on little prob.
one of my fields is a time field. It's showing up on the datagrid as a date...
How do I set the conversion processes.
In access I would use an Import Spec to define my fields. How is this done in vb?
tia
jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top