Link to home
Start Free TrialLog in
Avatar of jxharding
jxharding

asked on

cant load CSV into dataset - IE displays file does not exist, but it does - code supplied, prob small error

it's a simple task, use asp.net to load a csv file into a dataset.
the file exists : if i copy and paste the "c:\inetput\wwwroot\MyFolder\MyApp.csv" into browser, i access the file.
still i get the error file does not exist

i tried all the posts i could find, all of them use c# but the usage is the same.



    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
        Dim MyConnection As System.Data.OleDb.OleDbConnection

        MyConnection = New System.Data.OleDb.OleDbConnection( _
        "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("/MyFolder/MyFile.csv") & ";Extended Properties=text")

        ' Select the data from Sheet1 of the workbook.
        MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)

        'DS = New System.Data.DataSet
        MyCommand.Fill(Extension1) '>>>>>>>> BOMBS OUT HERE
        MyConnection.Close()

        Me.DataGrid1.DataSource = Extension1
        Me.DataGrid1.DataBind()

    End Sub



Contents of CSV File : (No headers)
Barnabas,A,7528
Brains, Eric,7534


Please help me load this csv into dataset.
thanks!
Avatar of b1xml2
b1xml2
Flag of Australia image

1. is the web server the same as your box?
2. Virtual directories means that the actual file location may not under wwwroot.


Server.MapPath("~/MyFolder.MyFile.csv")
do the trick.

ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jxharding
jxharding

ASKER

yes, the web server is my box


'c:\inetpub\wwwroot\MyFolder\MyFile.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.

but if i copy that section , i access the file.

this is a really non descriptive error message from asp.

so should the code work in fact then?
Can the OLEDB Provider accept CSV files???
I dont think Jet can do that...
heh I was right:

  conn_excel_str = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="
                + HttpContext.Current.Server.MapPath(".//" + csv_store_read);
        //Server.MapPath(".//" + csv_store_read)
        //Path mapped to csv file temp stored on the server

you load the csv through this driver not the Jet Driver
well its still not working

is there any other method of text that you could help me with to load this file into the dataset? i dont know how to se the darn microsoft text driver in a vb.net connection string.
This post did not help at all. I accepted answer because it is going to stand still. Im pursuing another question.
Thanks
i was researching the answer, i will post the answer nonetheless.