if i create a sqladapter and fill my datatable it works fine -- old code
however, if i make a dataview of the sqldatasource and convert that to a datatable it errors
How do you convert a dataview to a datatable
code snippet below fail
Dim DVGridProject
As DataView =
CType(GridProjectDataSource.Select(DataSourceSelectArguments.Empty), DataView)
If DVGridProject.Table.Rows.Count > 0
Then
Try
' Response.Buffer = True
Dim sqlAdapter As SqlDataAdapter =
New SqlDataAdapter(command)
'create our datatable
Dim dataTable
As DataTable =
New DataTable
'fill the datatable with the values fetched from our query
The ToTable() method should create a new DataTable on what the DataView have.
Could you let me know what exception was thrown on which line?
I would suggest you try to check SqlDataSource.DataSourceMode property. Because the Select method returns a DataView object, if the DataSourceMode property is set to the DataSet value; or it will return a IDataReader object, if the DataSourceMode property
is set to the DataReader value. So make sure DataSourceMode has been set to DataSet.
Sincerely,
Kevin Yu
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Mark as Not Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
tpiazza
Member
55 Points
252 Posts
sqldatasource to datatable
Aug 14, 2007 12:20 PM|LINK
I am exporting the result of a query to excel
if i create a sqladapter and fill my datatable it works fine -- old code
however, if i make a dataview of the sqldatasource and convert that to a datatable it errors
How do you convert a dataview to a datatable
code snippet below fail
Dim DVGridProject As DataView = CType(GridProjectDataSource.Select(DataSourceSelectArguments.Empty), DataView) If DVGridProject.Table.Rows.Count > 0 Then Try ' Response.Buffer = TrueResponse.ContentType =
"Application/x-msexcel" Response.AddHeader("Content-disposition", "attachment; filename=""test.csv""")
Dim table As DataTable = DVGridProject.ToTable()then i call the function and it errors
this works fine -- whats the difference
Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter(command) 'create our datatable Dim dataTable As DataTable = New DataTable 'fill the datatable with the values fetched from our querysqlAdapter.Fill(dataTable)
Kevin Yu - M...
All-Star
19021 Points
1467 Posts
Re: sqldatasource to datatable
Aug 16, 2007 06:52 AM|LINK
Hi,
The ToTable() method should create a new DataTable on what the DataView have.
Could you let me know what exception was thrown on which line?
I would suggest you try to check SqlDataSource.DataSourceMode property. Because the Select method returns a DataView object, if the DataSourceMode property is set to the DataSet value; or it will return a IDataReader object, if the DataSourceMode property is set to the DataReader value. So make sure DataSourceMode has been set to DataSet.
Kevin Yu
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Mark as Not Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.