P
Prasun
Hello:
I am trying to display an Excel file in a DataGrid. I have Included my code.
It runs through with no exception, but nothing appears in the datagrid
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim XLConn As New OleDbConnection
XLConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Test_001.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
Dim XLCmd As New OleDbCommand
XLCmd.Connection = XLConn
Try
XLConn.Open()
Dim XLDA As New OleDbDataAdapter
Dim XLDS As New DataSet("MainDS")
Dim XLTableMain As DataTable = XLDS.Tables.Add("TableMainO")
XLCmd.CommandText = "SELECT * FROM [Sheet1$]"
XLDA.SelectCommand = XLCmd
XLDA.Fill(XLDS, "TableMainO")
Dim XLDV As New DataView
Dim XLDataGrid As New DataGrid
XLDV = New DataView(XLDS.Tables("TableMainO"))
XLDataGrid.DataSource = XLDS
XLDataGrid.DataMember = XLDS.Tables("TableMainO").ToString
XLDataGrid.SetDataBinding(XLDS, "TableMainO")
Finally
XLConn.Close()
End Try
End Sub
Thank You
Prasun
I am trying to display an Excel file in a DataGrid. I have Included my code.
It runs through with no exception, but nothing appears in the datagrid
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim XLConn As New OleDbConnection
XLConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Test_001.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
Dim XLCmd As New OleDbCommand
XLCmd.Connection = XLConn
Try
XLConn.Open()
Dim XLDA As New OleDbDataAdapter
Dim XLDS As New DataSet("MainDS")
Dim XLTableMain As DataTable = XLDS.Tables.Add("TableMainO")
XLCmd.CommandText = "SELECT * FROM [Sheet1$]"
XLDA.SelectCommand = XLCmd
XLDA.Fill(XLDS, "TableMainO")
Dim XLDV As New DataView
Dim XLDataGrid As New DataGrid
XLDV = New DataView(XLDS.Tables("TableMainO"))
XLDataGrid.DataSource = XLDS
XLDataGrid.DataMember = XLDS.Tables("TableMainO").ToString
XLDataGrid.SetDataBinding(XLDS, "TableMainO")
Finally
XLConn.Close()
End Try
End Sub
Thank You
Prasun