Using excel data in vb once its in my application..?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nimion
    New Member
    • Sep 2007
    • 11

    Using excel data in vb once its in my application..?

    For work I've been tasked with creating some verification programs. So I thought best way to do this is to take their excel sheet and compare the data...

    I've been able to open the excel sheet and place it into a DataGridView, but now I'm stumped on how I actually use the data Im seeing...

    I.E - The sheet has 2 columns (min) and (max) with about 20 rows of values... I want to be able to compare the data a user inputs against these two columns... so if the user enters the number 20, it makes sure its greater then any of the (min) values and less then any of the (max) values via a text box and button... any ideas?


    **Edit**
    Ok i figured out I can use the values from a datagrid using the

    DataGridMatrix( value,value) but As I'm trying to place it into a text it says it cannot be converted to 'string'.

    Oh! Im using VB.net '05 with my excel document being imported from the Excel 8.0 version, and below is my code to read the excel file.



    Dim sqlData As String = "SELECT * FROM [Sheet1$]"

    Dim xlCon As String = "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
    "Data Source=C:\Docum ents and Settings\eneal\ Desktop\matrix. xls;" & _
    "Extended Properties=""Ex cel 8.0;HDR=YES"""

    Dim conn As New OleDbConnection (xlCon)
    Dim db As New OleDbDataAdapte r(sqlData, conn)
    Dim dbExcelData As New DataSet
    db.Fill(dbExcel Data, "matrix")
    Me.DataGridMatr ix.DataSource = dbExcelData.Tab les("matrix")
    dbExcelData.Dis pose()
    db.Dispose()
    conn.Dispose()
  • VBPhilly
    New Member
    • Aug 2007
    • 95

    #2
    Originally posted by Nimion
    For work I've been tasked with creating some verification programs. So I thought best way to do this is to take their excel sheet and compare the data...

    I've been able to open the excel sheet and place it into a DataGridView, but now I'm stumped on how I actually use the data Im seeing...

    I.E - The sheet has 2 columns (min) and (max) with about 20 rows of values... I want to be able to compare the data a user inputs against these two columns... so if the user enters the number 20, it makes sure its greater then any of the (min) values and less then any of the (max) values via a text box and button... any ideas?


    **Edit**
    Ok i figured out I can use the values from a datagrid using the

    DataGridMatrix( value,value) but As I'm trying to place it into a text it says it cannot be converted to 'string'.

    Oh! Im using VB.net '05 with my excel document being imported from the Excel 8.0 version, and below is my code to read the excel file.



    Dim sqlData As String = "SELECT * FROM [Sheet1$]"

    Dim xlCon As String = "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
    "Data Source=C:\Docum ents and Settings\eneal\ Desktop\matrix. xls;" & _
    "Extended Properties=""Ex cel 8.0;HDR=YES"""

    Dim conn As New OleDbConnection (xlCon)
    Dim db As New OleDbDataAdapte r(sqlData, conn)
    Dim dbExcelData As New DataSet
    db.Fill(dbExcel Data, "matrix")
    Me.DataGridMatr ix.DataSource = dbExcelData.Tab les("matrix")
    dbExcelData.Dis pose()
    db.Dispose()
    conn.Dispose()

    What is the code causing the conversion error?

    Comment

    • Nimion
      New Member
      • Sep 2007
      • 11

      #3
      Private Sub DataGridMatrix_ CellContentClic k(ByVal sender As System.Object, ByVal e As System.Windows. Forms.DataGridV iewCellEventArg s) Handles DataGridMatrix. CellContentClic k

      txtdata.Text = DataGridMatrix( 4, 1)

      End Sub


      The error is:
      Value of type 'System.Windows .Forms.DataGrid ViewCell' cannot be converted to 'String'.

      I want the actual value of the cell to be placed into the textbox when I click it in DataGridView, I've got the 'location' several times..but thats not what I need : /

      Comment

      • VBPhilly
        New Member
        • Aug 2007
        • 95

        #4
        Originally posted by Nimion
        Private Sub DataGridMatrix_ CellContentClic k(ByVal sender As System.Object, ByVal e As System.Windows. Forms.DataGridV iewCellEventArg s) Handles DataGridMatrix. CellContentClic k

        txtdata.Text = DataGridMatrix( 4, 1)

        End Sub


        The error is:
        Value of type 'System.Windows .Forms.DataGrid ViewCell' cannot be converted to 'String'.

        I want the actual value of the cell to be placed into the textbox when I click it in DataGridView, I've got the 'location' several times..but thats not what I need : /
        what does this do:

        Code:
        txtData.Text = DataGridMatrix(4,1).ToString

        Comment

        • Nimion
          New Member
          • Sep 2007
          • 11

          #5
          That actually returned a value into my text box...but it returned this..



          DataGridViewTex tBoxCell { ColumnIndex=4, RowIndex=1 }

          Comment

          • VBPhilly
            New Member
            • Aug 2007
            • 95

            #6
            Originally posted by VBPhilly
            what does this do:

            Code:
            txtData.Text = DataGridMatrix(4,1).ToString
            Better still :) :

            Code:
            txtData.Text = DataGridMatrix(4,1).value

            Comment

            • Nimion
              New Member
              • Sep 2007
              • 11

              #7
              It worked...Haha. It was that easy..... -.- wow...I used every combination I could think of but the obvious eluded me... thanks a lot :)

              Comment

              Working...