W
WalangAlam
Guest
How to convert excel file to sql server express 2005 database file (mdf)
Dim MyConnection As System.Data.OleDb.OleDbConnection
Try
Dim DS As System.Data.DataSet
Dim strPath, strSheet As String
strPath = "c:\Test.xls"
strSheet = "Sheet1"
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & strPath & ";Extended Properties=""Excel 8.0;IMEX=1;HDR=YES;""")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [" & strSheet & "$]", MyConnection)
DS = New System.Data.DataSet
MyCommand.Fill(DS)
Dim dv As DataView
dv = DS.Tables(0).DefaultView
DataGridView1.DataSource = dv
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try

