Hi,
with the below code im importing data from excel to gridview, Data is importing successfully, but if column have text and number data then it will take only either number or text data, if take number data then shows blank in text field data.
Example below excel file
| Item Code | Item Description |
| '000001 | Item A |
| 2 | Item B |
| 3 | Item C |
In this case First row 000001 shows blank in GridView
Dim conn As OleDbConnection
Dim dtr As OleDbDataReader
Dim dta As OleDbDataAdapter
Dim cmd As OleDbCommand
Dim dts As DataSet
Dim excel As String
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "All Files (*.*)|*.*|Excel files (*.xlsx)|*.xlsx|CSV Files (*.csv)|*.csv|XLS Files (*.xls)|*xls"
If (OpenFileDialog1.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
excel = OpenFileDialog1.InitialDirectory + OpenFileDialog1.FileName
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties=Excel 12.0;")
dta = New OleDbDataAdapter("Select * From [Sheet1$]", conn)
dts = New DataSet
dta.Fill(dts, "[Sheet1$]")
DataGridView1.DataSource = dts
DataGridView1.DataMember = "[Sheet1$]"
conn.Close()
End If
Thanks
Basit.

Basit KhanRank #4,768 · 326 reputationPosted Feb 12, 2018, 7:09 PM EST
Suraj KumarRank #353 · 7.1K reputationPosted Feb 12, 2018, 6:38 PM EST
Laxmidhar SahooRank #383 · 6.6K reputationPosted Feb 12, 2018, 7:31 PM EST
Suraj KumarRank #353 · 7.1K reputationPosted Feb 12, 2018, 7:58 PM EST
Pusting72 reputationPosted Feb 13, 2018, 8:39 PM EST