471,330 Members | 1,239 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to import a CSV file into a Datagrid - VB.NET

Please help point me in the right direction to import a CSV file into a

Below is the error I'm receiving, OLE csv format file, sample CSV file, and
code I've tried to no success.

I've made sure that the path is valid in windows explorer, and the NTFS
security is set to Everyone and ASP.NET full access.

Thank you in advance


System.Data.OleDb.OleDbException: 'C:\Inetpub\wwwroot\dev\Data\dev.csv' is
not a valid path. Make sure that the path name is spelled correctly and that
you are connected to the server on which the file resides. at
System.Data.OleDb.OleDbConnection.ProcessResults(I nt32 hr) at
System.Data.OleDb.OleDbConnection.InitializeProvid er() at
System.Data.OleDb.OleDbConnection.Open() at
Attachments.ImportTimco.btnReview_ServerClick(Obje ct sender, EventArgs e) in
'C:\Inetpub\wwwroot\dev\dev.aspx.vb:line 79

CSV.TXT schema file for OleDb:

Col1=OtherID Char Width 10
Col2=ClockDate Char Width 10
Col3=Hours Char Width 5
Col4=FullName Char Width 20
CSV Data file sample:

97369,1/29/2005,8,"SAQUILON, ALFREDO"
97369,1/30/2005,8,"SAQUILON, ALFREDO"
97369,1/31/2005,7.65,"SAQUILON, ALFREDO"

If Not File1.PostedFile Is Nothing And
File1.PostedFile.ContentLength > 0 Then
Dim strConnectionString As String
Dim strPathToTextFile As String
Dim tempString As String
strPathToTextFile = File1.PostedFile.FileName
strConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathToTextFile & ";" & _
"Extended Properties=""text;HDR=NO;FMT=Delimited"""
Dim objConnection As New
System.Data.OleDb.OleDbConnection(strConnectionStr ing)

Dim objDA As New OleDbDataAdapter("SELECT * FROM
CSV.txt", objConnection)


If ((ds.ToString <> "") And (ds.Tables(0).Rows.Count >
0)) Then
DataGrid1.DataSource = ds

End If

Catch ex As Exception
End Try

Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Response.Write("Please select a file to upload")
End If
Jul 21 '05 #1
1 6816
strPathToTextFile in your code actually includes the name of your csv
file when it shouldn't. It should only contain the path to the folder
that the csv file resides in.

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Rahul Gupta | last post: by

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.