By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

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

P: 11
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=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\eneal\Desktop\matrix.xls;" & _
"Extended Properties=""Excel 8.0;HDR=YES"""

Dim conn As New OleDbConnection(xlCon)
Dim db As New OleDbDataAdapter(sqlData, conn)
Dim dbExcelData As New DataSet
db.Fill(dbExcelData, "matrix")
Me.DataGridMatrix.DataSource = dbExcelData.Tables("matrix")
dbExcelData.Dispose()
db.Dispose()
conn.Dispose()
Sep 10 '07 #1
Share this Question
Share on Google+
6 Replies


VBPhilly
P: 95
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=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\eneal\Desktop\matrix.xls;" & _
"Extended Properties=""Excel 8.0;HDR=YES"""

Dim conn As New OleDbConnection(xlCon)
Dim db As New OleDbDataAdapter(sqlData, conn)
Dim dbExcelData As New DataSet
db.Fill(dbExcelData, "matrix")
Me.DataGridMatrix.DataSource = dbExcelData.Tables("matrix")
dbExcelData.Dispose()
db.Dispose()
conn.Dispose()

What is the code causing the conversion error?
Sep 10 '07 #2

P: 11
Private Sub DataGridMatrix_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridMatrix.CellContentClick

txtdata.Text = DataGridMatrix(4, 1)

End Sub


The error is:
Value of type 'System.Windows.Forms.DataGridViewCell' 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 : /
Sep 10 '07 #3

VBPhilly
P: 95
Private Sub DataGridMatrix_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridMatrix.CellContentClick

txtdata.Text = DataGridMatrix(4, 1)

End Sub


The error is:
Value of type 'System.Windows.Forms.DataGridViewCell' 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:

Expand|Select|Wrap|Line Numbers
  1. txtData.Text = DataGridMatrix(4,1).ToString 
  2.  
Sep 10 '07 #4

P: 11
That actually returned a value into my text box...but it returned this..



DataGridViewTextBoxCell { ColumnIndex=4, RowIndex=1 }
Sep 10 '07 #5

VBPhilly
P: 95
what does this do:

Expand|Select|Wrap|Line Numbers
  1. txtData.Text = DataGridMatrix(4,1).ToString 
  2.  
Better still :) :

Expand|Select|Wrap|Line Numbers
  1. txtData.Text = DataGridMatrix(4,1).value
  2.  
Sep 10 '07 #6

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

Post your reply

Sign in to post your reply or Sign up for a free account.