473,320 Members | 1,922 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,320 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 6942
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...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.