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 August 30th, 2004, 07:00 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default NullReferenceException updating a DataSet rows

hi every one i am getting this error when i am trying to update a row in table that i was created a row and assigned it some value and
add it to DataSet using Adding to DataSet using this code
Code:
 SqlConnection objSqlConnection=new SqlConnection(strConnection);
 SqlDataAdapter  objDataAdapter=new SqlDataAdapter("select id,count_all from counters",objSqlConnection)
try
{
   string selectCmd="update counters set count_all=@count where id=1";
   SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd,objSqlConnection);
   DataSet objDataSet=new DataSet();
   objDataAdapter.Fill(objDataSet,"counters");
// this portion of code dont work correctly nd seems dont intiate an object
    
Quote:
quote:DataTable objDataTable=new DataTable();
Quote:
   objDataTable=objDataSet.Tables["counters"];    DataRow objNewRow=objDataSet.Tables["counters"].NewRow();    objNewRow["count_all"]=100;    objDataSet.Tables["count_all"].Rows.Add(objNewRow);
    objDataAdapter.Update(objDataSet,"counters");    SqlCommandBuilder objCommandBuider=null;    objCommandBuider=new SqlCommandBuilder(objDataAdapter);    objDataAdapter.UpdateCommand=objCommandBuider.GetUpdateCommand();    objDataAdapter.Update(objDataSet,"counters");

Thanks In Advance .
YoOrD.


Beauty Is not in the face
Beauty is In 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 August 30th, 2004, 07:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Your select statement is an update statement. That's probably causing huge problems right there:

string selectCmd="update counters set count_all=@count where id=1";

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

Thanks for your replies.
what changes i must pply to them to work correct.
if i must change selectCommand to a select command(a select query only)is it what you like that i must to change.
Thanks In Advance.
YoOrD.

Beauty Is not in the face
Beauty is In the heart
--<<Ghibran Khalil>>--
 
Old August 30th, 2004, 10:00 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

i m change it to a select query but the problem persists.



Beauty Is not in the face
Beauty is In the heart
--<<Ghibran Khalil>>--
 
Old August 30th, 2004, 02:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You are going to need to provide the update statement also to the UpdateCommand, to get SQLDataAdapter.Update to work also.

Brian
 
Old September 1st, 2004, 04:04 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

I dont what changes i must appy to the code to work corect.
if you can give an example.
Thanks In Advance.
YoOrD.

Beauty Is not in the face
Beauty is In the heart
--<<Ghibran Khalil>>--
 
Old September 1st, 2004, 09:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

http://msdn.microsoft.com/library/de...datetopic2.asp
 
Old September 1st, 2004, 03:49 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

thanx 4 your replies.
YoOrD.

Beauty Is not in the face
Beauty is In the heart
--<<Ghibran Khalil>>--





Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating Database from Dataset hexOffender VB Databases Basics 0 October 30th, 2006 12:40 PM
updating a dataset hexOffender VB.NET 2002/2003 Basics 1 September 28th, 2006 05:13 PM
Fetching rows in dataset lily611 C# 4 April 27th, 2006 12:37 AM
Updating & Deleting Rows from a Repeater saturdave ASP.NET 1.0 and 1.1 Basics 4 February 19th, 2004 04:35 PM





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