ISPrincess
Programmer
Suffice it to say I need to get some samples out in a design very quickly - stored procs are not ready and tables are not filled with sample data, so...
I need to quickly hardcode (evil word) a dataset and then bind it to a data grid.
I have some code that is giving me errors, so I was hoping that
A) either someone could provide me with another bit of sample code to accomplish this
or
B) take a look at the following code (code sample gathered from another thread on this site)
and tell me what I am doing wrong
I have a grid datagrid1 defined on my page
In the page_load event I call
when I run the code, i get the error:
DataGrid with id 'Datagrid1' could not automatically generate any columns from the selected data source.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: DataGrid with id 'Datagrid1' could not automatically generate any columns from the selected data source.
Source Error:
Line 173:
Line 174: DataGrid1.DataSource = dsData.Tables(0)
Line 175: DataGrid1.DataBind()
Line 176:
Line 177: End Sub
Thank you very much !!
PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
I need to quickly hardcode (evil word) a dataset and then bind it to a data grid.
I have some code that is giving me errors, so I was hoping that
A) either someone could provide me with another bit of sample code to accomplish this
or
B) take a look at the following code (code sample gathered from another thread on this site)
and tell me what I am doing wrong
I have a grid datagrid1 defined on my page
In the page_load event I call
Code:
Private dsData As DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
InitializeDataSet()
FillDataSet()
end if
End sub
[code]
Public Sub InitializeDataset()
Dim dt As DataTable
dsData = New DataSet("ResourcePlanning")
dt = dsData.Tables.Add("ResourcePlanning")
dt.Columns.Add("Column1", GetType(SqlTypes.SqlString))
dt.Columns.Add("Column2", GetType(SqlTypes.SqlString))
dt.Columns.Add("Column3", GetType(SqlTypes.SqlInt16))
dt.Columns.Add("Column4", GetType(SqlTypes.SqlString))
End Sub
Public Sub FillDataSet()
Dim dt As DataTable
Dim dr As DataRow
dt = dsData.Tables(0)
dr = dt.NewRow
dr("VehicleType") = "Turret R"
dr = dt.NewRow
dr("Column1") = "Whatever"
dr("Column2") = "TTR123"
dr("Column3") = 1
dr("Column4") = "Comments for TTR123"
dr = dt.NewRow
dr("Column1") = "Whatever2"
dr("Column2") = "TTR890"
dr("Column3") = 0
dr("Column4") = "Comments for TTR890"
DataGrid1.DataSource = dsData.Tables(0)
DataGrid1.DataBind()
End Sub
when I run the code, i get the error:
DataGrid with id 'Datagrid1' could not automatically generate any columns from the selected data source.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: DataGrid with id 'Datagrid1' could not automatically generate any columns from the selected data source.
Source Error:
Line 173:
Line 174: DataGrid1.DataSource = dsData.Tables(0)
Line 175: DataGrid1.DataBind()
Line 176:
Line 177: End Sub
Thank you very much !!
PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips