I'm developing a program that will import excel to mysql. In the application, the user first of all has to load an excel file and then he will see that file load on a DataGridView.
The problem is that when the file is load it shows other values instead of excel one.
Here is an example in the excel file the value in red square is 1,49
While when the excel is load in DataTable > DataGridView it's 1,39...
Here is the method where I load excel in to DataGridView the dataGridView is called MetroGrid1
Private Sub Upload_Click(sender As Object, e As EventArgs) Handles BtnUpload.Click
Dim fd As OpenFileDialog = New OpenFileDialog()
Dim strFileName As String
fd.Title = "Seleziona file.."
fd.InitialDirectory = "C:\"
fd.Filter = "File Excel|*.xls;*.xlsx;*.xlsm"
fd.FilterIndex = 2
fd.RestoreDirectory = True
If fd.ShowDialog() = DialogResult.OK Then
strFileName = fd.FileName
TxtUpload.Text = ""
TxtUpload.Text = strFileName
Dim dt As New DataTable
Try
Dim constring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFileName & ";Extended Properties=""Excel 12.0;HDR=YES;"""
Dim con As New OleDbConnection(constring & "")
con.Open()
Dim myTableName = con.GetSchema("Tables").Rows(0)("TABLE_NAME")
Dim sqlquery As String = String.Format("SELECT * FROM [{0}]", myTableName)
Dim da As New OleDbDataAdapter(sqlquery, con)
da.Fill(dt)
MetroGrid1.DataSource = dt
For Each c As DataGridViewColumn In MetroGrid1.Columns
c.ReadOnly = True
c.SortMode = DataGridViewColumnSortMode.NotSortable
Next
PictureBox1.Visible = False
con.Close()
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical)
End Try
End If
End Sub
Actually I think that the value is wrong as in excel 1,49 is get from a formula =D2*(1-0,01*E2)*(1-0,01*F2)*2,44 but if the problem is the following, how can I import the right value?
UPDATE: Actually i've found the problem, the data in client excel file is formatted to 0,09 so the value of 1,39 become 1,49 so the value was the right one.
UPDATE 2 By setting IMEX=1 and HDR=NO i get the correct value but i still need the header.