 |
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
|
|
|
|
|

August 30th, 2004, 07:00 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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>>--
__________________
YoOrD .
Beauty is not on the face
Beauty is on the heart
~~<<Ghibran Khalil>>~~
|
|

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

August 30th, 2004, 09:51 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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>>--
|
|

August 30th, 2004, 10:00 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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>>--
|
|

August 30th, 2004, 02:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
You are going to need to provide the update statement also to the UpdateCommand, to get SQLDataAdapter.Update to work also.
Brian
|
|

September 1st, 2004, 04:04 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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>>--
|
|

September 1st, 2004, 09:14 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
|
|

September 1st, 2004, 03:49 PM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
thanx 4 your replies.
YoOrD.
Beauty Is not in the face
Beauty is In the heart
--<<Ghibran Khalil>>--
|
|
 |