Results 1 to 5 of 5

Thread: CSV Import into gridview problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    CSV Import into gridview problem

    Hi

    I posted this in the ASP forums but think its more of a vb question so sorry for the repost:

    I have an app that will load info from a csv into a gridview. Everything works properly except for one column. It is only displaying fields with numeric values. All of the alpha-numeric cells are being left blank. I have looked at the csv and it is properly formatted and the other columns have alpha-numeric as well and are being pulled in properly.

    Here is a snippet of the code that populates the gridview. Any help would be most appreciated.

    Code:
            Dim savePath As String = "\\Depts\"
    
    
            Dim Conn As System.Data.Odbc.OdbcConnection
            Dim dt As New System.Data.DataTable
            Dim da As System.Data.Odbc.OdbcDataAdapter
            Dim strConnstr, strImportfolder, strFilename As String
    
    
    
            strFilename = FileUpload1.FileName
            'this is the csv file to be imported
    
            strConnstr = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + savePath + ";"
            Conn = New System.Data.Odbc.OdbcConnection(strConnstr)
    
            da = New System.Data.Odbc.OdbcDataAdapter("SELECT Site, Line , Item, Date  FROM [" + strFilename + "]", Conn)
            da.Fill(dt)
            Session("Import") = dt
            GridView1.DataSource = Session("Import")
            GridView1.DataBind()
    The Item column is the one that is coming in incorrectly.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    Re: CSV Import into gridview problem

    I found that the majority of cells need to be alpha-numeric. That is odd to me. Is there anything I can do to the select statement to tell it that is not numeric?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    Re: CSV Import into gridview problem

    I have tried doing "SELECT CStr(Item)......."
    but now getting an "invalid use of null" when i fill the da

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    Re: CSV Import into gridview problem

    Strange, it is making the alpha-numeric cells null before evaluating them against the Cstr() function. I am stumped

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    Re: CSV Import into gridview problem

    So any ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width