473,386 Members | 1,694 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,386 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 6946
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.