Unix Technical Forum

Displaying a CHAR FOR BIT DATA in C#

This is a discussion on Displaying a CHAR FOR BIT DATA in C# within the DB2 forums, part of the Database Server Software category; --> ///C# Code OdbcConnection con = new OdbcConnection(connection string); con.Open(); OdbcCommand cmd = new OdbcCommand("select nsilunique_id from nstbale",con); OdbcDataReader dr ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 05:44 AM
jburkle19@gmail.com
 
Posts: n/a
Default Displaying a CHAR FOR BIT DATA in C#

///C# Code

OdbcConnection con = new OdbcConnection(connection string);
con.Open();
OdbcCommand cmd = new OdbcCommand("select nsilunique_id from
nstbale",con);
OdbcDataReader dr = cmd.ExecuteReader();
this.dgOrders.DataSource = dr;
this.dgOrders.DataBind();

When I bind that data to a column it displays:

System.Byte[] instead of the value in the coulmn which looks like
'200511120000002020000'

I tried casting it to a varchar in the SQL call, and storing it as a
string in the C# and either way it doesn't display in value.

I want it to return the '200511120000002020000' as somekind of string
so i can break it apart and create a date out of the first 8 digits of
it.

Any suggestions? I scoured the internet and couldn't find a solution.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 05:45 AM
Serge Rielau
 
Posts: n/a
Default Re: Displaying a CHAR FOR BIT DATA in C#

jburkle19@gmail.com wrote:
> ///C# Code
>
> OdbcConnection con = new OdbcConnection(connection string);
> con.Open();
> OdbcCommand cmd = new OdbcCommand("select nsilunique_id from
> nstbale",con);
> OdbcDataReader dr = cmd.ExecuteReader();
> this.dgOrders.DataSource = dr;
> this.dgOrders.DataBind();
>
> When I bind that data to a column it displays:
>
> System.Byte[] instead of the value in the coulmn which looks like
> '200511120000002020000'
>
> I tried casting it to a varchar in the SQL call, and storing it as a
> string in the C# and either way it doesn't display in value.
>
> I want it to return the '200511120000002020000' as somekind of string
> so i can break it apart and create a date out of the first 8 digits of
> it.
>
> Any suggestions? I scoured the internet and couldn't find a solution.
>

Well, if you now C# all you need to no is to decode the BCD packed.
Anyway. Assuming the column is timestamp (by the looks of it) try this:
select rtrim(char(integer(date(nsilunique_id)))) from nstbale

date() will truncate the time
integer() will turn the date into an integer of the form 2005112
char() will turn teh inteer into '20051112 '
RTRIM() will trim the trailing spaces.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 05:45 AM
Knut Stolze
 
Posts: n/a
Default Re: Displaying a CHAR FOR BIT DATA in C#

jburkle19@gmail.com wrote:

> ///C# Code
>
> OdbcConnection con = new OdbcConnection(connection string);
> con.Open();
> OdbcCommand cmd = new OdbcCommand("select nsilunique_id from
> nstbale",con);
> OdbcDataReader dr = cmd.ExecuteReader();
> this.dgOrders.DataSource = dr;
> this.dgOrders.DataBind();
>
> When I bind that data to a column it displays:
>
> System.Byte[] instead of the value in the coulmn which looks like
> '200511120000002020000'


CHAR FOR BIT DATA is binary data. So I'd say that the data type is exactly
what it ought to be. IF you want to convert the binary data to the
hex-representation, you have to resort to whatever facilities C# provides
for that.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:56 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com