B
Brian Newtz
Hello!
I have a slight problem. I'm making a dynamic database query engine with ASP.NET. I have a datagrid that must auto generate the columns (since it can bind to any column), and my database contains GUID columns. When I try to databind the datagrid to a table containing a GUID column (that the user picked to show), the GUID column is not shown. According to KB Article 313155, this behavior is by design.
However, the method shown in the article to work around the problem does not seem to work (Method 1). I've tried placing their code snippet in 3 spots:
1. before setting the datagrid's datasource property
2. after setting the datagrid's datasource property
3. after calling datagrid.databind (which this one shouldn't work, but I tried anyways).
All three attempts don't work. I always get the same error if the only columns returned are guid columns (if there are other 'normal' columns, the normal columns get generated and I don't get an error - the guid column is missing however):
"DataGrid with id 'dgResults' could not automatically generate any columns from the selected data source."
The error occurs on the dgResults.DataBind() statement.
My code is as follows (the conn.GetTableData method builds a select command from the columns (string[] parameter) from the specified table and database, and executes the command, returning a datatable with the data):
[start code]
DataTable t = conn.GetTableData(columns, ddlTables.SelectedValue, ddlDatabases.SelectedValue);
foreach(DataColumn c in t.Columns)
{
if (c.DataType == Type.GetType("System.Guid"))
{
BoundColumn bc = new BoundColumn();
bc.DataField = c.ColumnName;
bc.HeaderText = c.ColumnName;
dgResults.Columns.Add(bc);
}
}
dgResults.DataSource = t;
dgResults.DataBind();
[end code]
I have verified that the bound columns are, in fact, getting created if there is a guid column by stepping through the code with the debugger.
Any suggestions?
Thanks in advance,
-Brian
I have a slight problem. I'm making a dynamic database query engine with ASP.NET. I have a datagrid that must auto generate the columns (since it can bind to any column), and my database contains GUID columns. When I try to databind the datagrid to a table containing a GUID column (that the user picked to show), the GUID column is not shown. According to KB Article 313155, this behavior is by design.
However, the method shown in the article to work around the problem does not seem to work (Method 1). I've tried placing their code snippet in 3 spots:
1. before setting the datagrid's datasource property
2. after setting the datagrid's datasource property
3. after calling datagrid.databind (which this one shouldn't work, but I tried anyways).
All three attempts don't work. I always get the same error if the only columns returned are guid columns (if there are other 'normal' columns, the normal columns get generated and I don't get an error - the guid column is missing however):
"DataGrid with id 'dgResults' could not automatically generate any columns from the selected data source."
The error occurs on the dgResults.DataBind() statement.
My code is as follows (the conn.GetTableData method builds a select command from the columns (string[] parameter) from the specified table and database, and executes the command, returning a datatable with the data):
[start code]
DataTable t = conn.GetTableData(columns, ddlTables.SelectedValue, ddlDatabases.SelectedValue);
foreach(DataColumn c in t.Columns)
{
if (c.DataType == Type.GetType("System.Guid"))
{
BoundColumn bc = new BoundColumn();
bc.DataField = c.ColumnName;
bc.HeaderText = c.ColumnName;
dgResults.Columns.Add(bc);
}
}
dgResults.DataSource = t;
dgResults.DataBind();
[end code]
I have verified that the bound columns are, in fact, getting created if there is a guid column by stepping through the code with the debugger.
Any suggestions?
Thanks in advance,
-Brian