R
Ryan
Hi all,
I'm loading a datagridview from an Excel file using a dataadapter.fill()
method. A few questions:
1) Is there any way to control the column datatypes? The columns are
defined by the .fill method based on the excel file, and the data is read in
during the .file method, so everything happens with this one command. If I
try to define a column.datatype before calling .fill I get an error because
the column doesn't exist yet, if I try to define the column.datatype after
..fill I get an error because you can't change a columns datatype once data
exists in the datatable.
2) Is there any way to have a progress bar monitor the progress of the .fill
method. Again everything happens with this single command so I don't have
anywhere to place code.
Heres my code:
Dim connString As String = "Driver={Microsoft Excel Driver (*.xls)};DBQ=" &
Me.OpenFileDialog1.FileName
Dim da As New System.Data.Odbc.OdbcDataAdapter
Dim ds As DataSet = New DataSet
Dim myRecords As Integer
Using cn As New System.Data.Odbc.OdbcConnection(connString)
cn.Open()
da.SelectCommand = New System.Data.Odbc.OdbcCommand("Select * from
[Sheet1$]", cn)
myRecords = da.Fill(ds)
Me.DataGridViewCoFile.DataSource = ds.Tables(0)
End Using
Thanks,
Ryan
I'm loading a datagridview from an Excel file using a dataadapter.fill()
method. A few questions:
1) Is there any way to control the column datatypes? The columns are
defined by the .fill method based on the excel file, and the data is read in
during the .file method, so everything happens with this one command. If I
try to define a column.datatype before calling .fill I get an error because
the column doesn't exist yet, if I try to define the column.datatype after
..fill I get an error because you can't change a columns datatype once data
exists in the datatable.
2) Is there any way to have a progress bar monitor the progress of the .fill
method. Again everything happens with this single command so I don't have
anywhere to place code.
Heres my code:
Dim connString As String = "Driver={Microsoft Excel Driver (*.xls)};DBQ=" &
Me.OpenFileDialog1.FileName
Dim da As New System.Data.Odbc.OdbcDataAdapter
Dim ds As DataSet = New DataSet
Dim myRecords As Integer
Using cn As New System.Data.Odbc.OdbcConnection(connString)
cn.Open()
da.SelectCommand = New System.Data.Odbc.OdbcCommand("Select * from
[Sheet1$]", cn)
myRecords = da.Fill(ds)
Me.DataGridViewCoFile.DataSource = ds.Tables(0)
End Using
Thanks,
Ryan