0

I have following code that reads data using OleDbDataReader.

The funny thing is that I can only return numbers although I converted to string.

Dim cn As New OleDbConnection
Dim fileloc = Server.MapPath("~/test/")
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileloc + ";Extended Properties='text;HDR=Yes;FMT=Delimited'"
cn.Open()

Dim cmd As New OleDbCommand
    cmd.Connection = cn
    cmd.CommandText = "SELECT * FROM feed.csv"

Dim reader As OleDbDataReader = cmd.ExecuteReader()
While reader.Read()
    Response.Write(reader("Stock Number").ToString)
End While
reader.Close()
cn.Close()

So I opened the csv file with test and looked the data.

When ever "Stock Number" has string, it doesn't not return data.

IM-95-189-012 ----> returns blank

2241 -----> returns 2241

2241B -----> returns blank

This is the first time I work with OleDbDataReader.

Any idea what's going on ?

shinya
  • 403
  • 2
  • 9
  • 23

1 Answers1

1

If you are always trying to get a string value, then use GetString. If you need more info, check the knowledge base

Response.Write(reader.GetString("Stock Number"))

This has a direct impact on this. Answer is for C#, but should be convertible to VB.

Community
  • 1
  • 1
APrough
  • 2,671
  • 3
  • 23
  • 31
  • Thank you for your help. I tried your code but I'm getting "Input string was not in a correct format" Error. I've been googling and found this site. This person is getting exactly same issue. http://www.codeproject.com/Questions/268732/Csharp-upload-csv-column-data-type-problem – shinya Feb 06 '12 at 18:07
  • Interesting. If I see anything else regarding this, I'll let you know. – APrough Feb 06 '12 at 18:18
  • Edited above to include link to solution for C#. – APrough Feb 06 '12 at 18:32
  • I guess I need to create Schema.ini file... Anyway, Thank you so much! – shinya Feb 06 '12 at 19:01
  • Not a problem. I have a feeling one of my next projects involves something similar, so I will consider this research! – APrough Feb 06 '12 at 19:05