Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 10-22-2009, 05:23 PM   PM User | #1
ghell
Senior Coder

 
Join Date: Apr 2003
Location: Surrey, England
Posts: 1,179
Thanks: 5
Thanked 12 Times in 12 Posts
ghell is on a distinguished road
Binary columns in a DataGrid bound to a DataReader

I am trying to use a System.Web.UI.WebControls.DataGrid with a SqlDataReader as the data source.

The DataReader may contain a wide variety of data so I do not know which columns I will need in advance.

This all works well apart from for Binary data (such as a varbinary type in SQL Server 2005). It just skips these columns entirely. If I try to use just a binary column in the query, I get the following error:
Quote:
System.Web.HttpException: DataGrid with id 'SqlDataGrid' could not automatically generate any columns from the selected data source.
Is there any way to define how to generate these columns? I always want them to just display as hex, as they would in SQL Management Studio.
__________________
My tech/code blog
ghell is offline   Reply With Quote
Old 11-06-2009, 06:22 PM   PM User | #2
SouthwaterDave
Regular Coder

 
Join Date: May 2007
Location: UK
Posts: 166
Thanks: 0
Thanked 18 Times in 18 Posts
SouthwaterDave is on a distinguished road
I see you are still using a DataGrid. Are you using an old version of ASP.NET? 1.0 or 1.1, perhaps?

The ObjectDataSource could be the answer to your problem but I think it was only introduced in ASP.NET 2.0.

See http://quickstarts.asp.net/QuickStar...lang=VB+Source for an example of how to use an object data source with a GridView. The select method of the data source class executes SQL and puts the results into a DataTable. You can add code to transform columns or add columns, as required, before returning the results to the web page.

(You can use AutoGenerateColumns="True" for your GridView if the user is allowed to make choices that affect the number or type of columns output to the web page.)
SouthwaterDave is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:30 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.