472,980 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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

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

ERROR:

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:

ColNameHeader=False
Format=CSVDelimited
MaxScanRows=0
CharacterSet=UNICODE
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"
CODE:

If Not File1.PostedFile Is Nothing And
File1.PostedFile.ContentLength > 0 Then
Try
Try
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)

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

objDA.Fill(ds)

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

End If
objConnection.Close()

Catch ex As Exception
Response.Write(ex.ToString())
End Try

Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload")
End If
Jul 21 '05 #1
1 6922
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rahul Gupta | last post by:
Hello Group, I want to import the csv format data into my progrm frm C# using oledb/odbc. Is it possible, how? Please Help, Rahul.
1
by: Rob | last post by:
Please help point me in the right direction to import a CSV file into a Datagrid. Below is the error I'm receiving, OLE csv format file, sample CSV file, and code I've tried to no success. ...
4
by: bluewind44 | last post by:
Hello, I made a page that used for import data from .xls files. At this page, users upload the .xls file to the server, then the app uses an OleDB connection and the Jet provider to read the data...
0
by: santosh1234 | last post by:
Hi, I have a problem in importing from an excel file. I am using the connection string for oledb to convert the data from the excel file into a datatable and proceed thereafter. Code I am using...
3
by: harshala | last post by:
I want to open excel file using open dialogue box and display records in datagrid
3
by: sena0112 | last post by:
Hi, I'm a beginner in visual basic and programming. My programme needs to let the user browse for a text file and when the user press a command button, the programme will list out the text file into...
3
by: vj83 | last post by:
Hi, I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form. The code is here private void Button2_Click(object sender,...
1
by: Amit | last post by:
Hello , Is there any way i can import data from datagrid to sqlserver. please advise . thanks & Regards
1
by: yemyem | last post by:
Hi Guys, im new to the c# language and im liking it so far. What im currently trying to do is write a windows form application so that when the user clicks on a button the application will read...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.