|
 |
ado_dotnet thread: Reading identity field from a DataReader
Message #1 by "John Tyson" <jtyson@t...> on Thu, 18 Apr 2002 13:21:26 -0700
|
|
Hi there,
I have created a Web page where I am trying to read data from a table in
a SQL Server 2000 database with a DataReader. The table is very simple
and consists of an identity/primary key field and a nvarchar-type field.
By selecting the nvarchar field alone I am able to read the first record
and output onto my Web page; however, when I try and also read the
identity field and output it like this
dr.Read()
lblBodyPart.Text =3D dr.GetInt32(0) + ", " + dr.GetString(1)
I get "Input String was not in correct format" server error. Can
identity fields be read and output using a DataReader?
Any help would be appreciated!
Thanks,
John
Message #2 by "Kyle" <Kyle@T...> on Thu, 18 Apr 2002 16:40:26 -0400
|
|
If you want to concatenate your identity field and your primary key as a
single string then you must use the string property of your identity
field
Try:
lblBodyPart.Text =3D dr.GetInt32(0).ToString() + ", " + dr.GetString(1);
Kyle
-----Original Message-----
From: John Tyson [mailto:jtyson@t...]
Sent: Thursday, April 18, 2002 4:21 PM
To: ADO.NET
Subject: [ado_dotnet] Reading identity field from a DataReader
Hi there,
I have created a Web page where I am trying to read data from a table in
a SQL Server 2000 database with a DataReader. The table is very simple
and consists of an identity/primary key field and a nvarchar-type field.
By selecting the nvarchar field alone I am able to read the first record
and output onto my Web page; however, when I try and also read the
identity field and output it like this
dr.Read()
lblBodyPart.Text =3D dr.GetInt32(0) + ", " + dr.GetString(1)
I get "Input String was not in correct format" server error. Can
identity fields be read and output using a DataReader?
Any help would be appreciated!
Thanks,
John
|
|
 |