Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > BOOK: Beginning ASP.NET 1.0
|
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 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 September 14th, 2004, 01:18 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default Specified cast is not valid in DataRow Casting

hi every one i encountered with some thing like this when i fetch a record from database using ADO.NET and using below code
Code:
DataSet objDataSet=new DataSet();
objSqlDA_G.Fill(objDataSet,"counters");
SqlCommandBuilder objSqlComBuld=new SqlCommandBuilder(objSqlDA_G);
DataTable objDT_G=objDataSet.Tables["counters"];
DataRow objRW_G=objDT_G.Rows[0];
//This line cause InvalidCastException: Specified cast is not valid.
 
Quote:
quote:Application["counter"]=(Int32)objRW_G["count_all"]+100;
The count_all column type is bigint in data base i like to fetch it and increment and updating it.
any one help what i must to change.
Thanx In Advance.
YoOrD.

Beauty Is not onthe face
Beauty is on the heart
--<<Ghibran Khalil>>--
__________________
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;YoOrD .
Beauty is not on the face
Beauty is on the heart
~~&lt;&lt;Ghibran Khalil&gt;&gt;~~
 
Old September 15th, 2004, 07:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Probably should check for null value before you do anything with it:

if (!objRW_G.IsNull("count_all")) {
    Application["counter"] ...
}

Brian
 
Old September 15th, 2004, 09:31 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

it is no a null value error it is a casting error object and an integer.
Thanks for your reply.
Thanks In Advance .
YoOrD.

Beauty Is not on the face
Beauty is on the heart
--<<Ghibran Khalil>>--
 
Old September 15th, 2004, 10:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try removing the +100 and see if it still gives you the same error.

 
Old September 15th, 2004, 10:30 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

but i like to increment the value and update the value to data source
i put the 100 for examination purpose only and i like to increment the content value of the row and postback to DB and in other place remove or decrement the value of row.
Beauty Is not on the face
Beauty is on the heart
--<<Ghibran Khalil>>--
 
Old September 15th, 2004, 10:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

What is the exact error?

I was thinking maybe you need to convert it int then add the 100 after the conversion.

 
Old September 15th, 2004, 12:19 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

i want to fetch value from DB And Increment it and finally Update DB
to affect the value.
and i am using DataSet To Fetch Value And DataTable And DataRow Collection to display the value but how i can change the value of a Row using Casting or other style .
i am getting error when i am increment the value of a column of row
becuase it seems it is a class and not a proper value .
when i am using casting like this
 
Quote:
quote:
Quote:
(Int32)objRW_G["count_all"]+1;
i am get this error
 
Quote:
quote:
Quote:

Line 100: Application["counter"]=(Int32)objRW_G["count_all"]+1;
Line 101: }
Line 102:

Specified cast is not valid.
and i am getting confued how i can change specific row value.
Than for your reply.
Thanks in Advance.
YoOrD.

Beauty Is not on the face
Beauty is on the heart
--<<Ghibran Khalil>>--
 
Old September 15th, 2004, 02:33 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi every one can help me about this prolem.
i think i must cast it to int but it is not castable(!!!!?????)
any if have any idea guide me i am apperciate.
Thanks In Advance.
YoOrD.

Beauty Is not on the face
Beauty is on the heart
--<<Ghibran Khalil>>--
 
Old September 15th, 2004, 02:36 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by stu9820
 What is the exact error?

I was thinking maybe you need to convert it int then add the 100 after the conversion.

But i Cast it using this role (Int32)Row_g("cname");
But the problem persist and i dont know how i cast it to do this.

Beauty Is not on the face
Beauty is on the heart
--<<Ghibran Khalil>>--
 
Old September 15th, 2004, 02:38 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks for your replies
but i know i hasn't Null
Quote:
quote:Originally posted by bmains
 Hey,

Probably should check for null value before you do anything with it:

if (!objRW_G.IsNull("count_all")) {
    Application["counter"] ...
}

Brian
Beauty Is not on the face
Beauty is on the heart
--<<Ghibran Khalil>>--





Similar Threads
Thread Thread Starter Forum Replies Last Post
Specified cast is not valid surajb Crystal Reports 0 January 12th, 2007 02:03 PM
Specified cast is not valid. abstar BOOK: ASP.NET Website Programming Problem-Design-Solution 2 March 31st, 2005 03:00 PM
"Specified cast is not valid" help BaBaBooey ASP.NET 1.0 and 1.1 Basics 2 November 23rd, 2004 12:12 PM
Specified cast is not valid TheMole BOOK: ASP.NET Website Programming Problem-Design-Solution 9 November 1st, 2004 05:09 PM





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