Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2007, 11:25 AM
Authorized User
 
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default bit column in datagrid

Hi. I sort of at a stand still right now with a datagrid. I have a bit column in my database and if the field = 0, in the datagrid it needs to display No and if the field = 1, it should display Yes. I'm having a hard time with this. Could someone help me?

 
Old December 6th, 2007, 11:41 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can do it one of 2 ways. The first way would be to use a case statement in your SQL:

SELECT
     case <bitcolumn>
       when 1 then 'Yes'
       else 'No'
     end as <columnName>
From <table>

or you can handle the RowDataBound event of the datagrid and manipulate the value there as the row gets bound to the datasource. Do a google search on how to handle this event if that is the route you want to go.

hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old December 6th, 2007, 11:50 AM
Authorized User
 
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you talking about like this? Because it keeps throwing up the error "Incorrect syntax near the keyword 'CASE'."

Select vchCompanynumber, vchAAPNumber, vchCompanyName, vchAAPFirstname, vchAAPLastName, bActive

CASE bActive

WHEN 0 THEN
        "No"
    WHEN 1 THEN
        "Yes"
    END as bActive

from tblAAPInfo

where vchCompanynumber like @conumber or vchAAPNumber like @APNumber or vchCompanyname like @coname or vchAAPfirstname like @first or vchAAPlastname like @last or bactive like @bactive

 
Old December 6th, 2007, 11:55 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No. You will want it to look like this:
Select vchCompanynumber, vchAAPNumber, vchCompanyName, vchAAPFirstname, vchAAPLastName,

CASE bActive

WHEN 0 THEN
        "No"
    WHEN 1 THEN
        "Yes"
END as bActive

from tblAAPInfo

Also, I tested this against SQL Server if you are using Access or another RDBMS such as MySQL the syntax may be different.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old December 6th, 2007, 12:20 PM
Authorized User
 
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help. I got it working.

 
Old December 6th, 2007, 12:34 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Glad it worked for you.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting column name/header of a datagrid elygp ASP.NET 1.0 and 1.1 Professional 2 June 6th, 2007 01:07 PM
64 Bit - Issue in 64 bit IIS calling Win32 API Hubman General .NET 1 August 24th, 2006 09:19 AM
Add a Column to a DataGrid infernokodiak C# 7 January 18th, 2006 04:06 PM
DataGrid Multi-Column pbyrum Classic ASP Professional 4 October 5th, 2005 06:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.