I am reading an Excel file into a dataset and using the dataset to populate a datagrid.
The problem I have is that I need to be able to set the data grid column title names. Column names are appearing but I need to change them for display on the datagrid.
How can I assign column names within a dataset or modify the datagrid column names?
My Code:-
Dim m_sConn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & OpenFileDialog1.FileName.ToString & _
";Extended Properties=""Excel 8.0;HDR=YES"""
'
' Define Connection To Excel
Dim ExcelConnection As New
System.Data.OleDb.OleDbConnection(m_sConn1)
'
' Define Command
Dim ExcelCommand As OleDbCommand = New OleDbCommand
ExcelCommand.CommandText = "SELECT * FROM [MySheet$]"
'
' Define DataAdapter
Dim ExcelDataAdapter As New OleDbDataAdapter
ExcelDataAdapter.SelectCommand = ExcelCommand
ExcelDataAdapter.SelectCommand.Connection =
ExcelConnection
'
' Define Dataset
Dim ExcelDataSet As New DataSet
'
' Get Dataset
ExcelConnection.Open()
ExcelDataAdapter.Fill(ExcelDataSet, "journals")
ExcelConnection.Close()
DataGrid1.DataSource = ExcelDataSet
DataGrid1.DataMember = "MySheet"
Dazed and confused
The problem I have is that I need to be able to set the data grid column title names. Column names are appearing but I need to change them for display on the datagrid.
How can I assign column names within a dataset or modify the datagrid column names?
My Code:-
Dim m_sConn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & OpenFileDialog1.FileName.ToString & _
";Extended Properties=""Excel 8.0;HDR=YES"""
'
' Define Connection To Excel
Dim ExcelConnection As New
System.Data.OleDb.OleDbConnection(m_sConn1)
'
' Define Command
Dim ExcelCommand As OleDbCommand = New OleDbCommand
ExcelCommand.CommandText = "SELECT * FROM [MySheet$]"
'
' Define DataAdapter
Dim ExcelDataAdapter As New OleDbDataAdapter
ExcelDataAdapter.SelectCommand = ExcelCommand
ExcelDataAdapter.SelectCommand.Connection =
ExcelConnection
'
' Define Dataset
Dim ExcelDataSet As New DataSet
'
' Get Dataset
ExcelConnection.Open()
ExcelDataAdapter.Fill(ExcelDataSet, "journals")
ExcelConnection.Close()
DataGrid1.DataSource = ExcelDataSet
DataGrid1.DataMember = "MySheet"
Dazed and confused