Datagrid GUID column - KB 313155 doesn't work

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
 
B

Brian Newtz

Anyone? I'd like to know if this can be resolved somehow...

Thanks,
Brian


Brian Newtz said:
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.
 
A

Alvin Bruney [MVP]

Brian,
please use this link to have microsoft technical support help you further
trouble shoot this issue
https://webresponse.one.microsoft.com/oas/public/assistedintro.aspx

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Brian Newtz said:
Anyone? I'd like to know if this can be resolved somehow...

Thanks,
Brian


Brian Newtz said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top