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 27th, 2004, 01:45 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default Problem In parameterized Sqladapter Update

hi every one i have problem with updating a row of database using
paramerized SqlCommand it is run without any error but dont affect table .
the code i am using for this updating is :
Code:
string strConnection="Data Source=myserver;Initial catalog=members;integrated security=SSPI;";
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);

myCommand.SelectCommand.Parameters.Add(new SqlParameter("@count", SqlDbType.NVarChar, 2));
myCommand.SelectCommand.Parameters["@count"].Value =100;
i dont know where i am have mistake that this code dont work properly.
if any one guide and reply me .
Thanks In Advance.
YoOrD.
__________________
       YoOrD .
Beauty is not on the face
Beauty is on the heart
~~<<Ghibran Khalil>>~~
 
Old August 27th, 2004, 02:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You need to execute the query.

objSqlConnection.Open();
myCommand.ExecuteNonQuery();
objSqlConnection.Close();

 
Old August 27th, 2004, 02:14 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

More Thanks for your reply imust exmine and check it work properly or not but so thank you .
Thanks in advance.
YoOrD.

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

hi every one
i am edit this code but the problem persist yet.
and i get this error now
Code:
string strConnection="Data Source=myserver;Initial catalog=members;integrated security=SSPI;";
SqlConnection objSqlConnection=new SqlConnection(strConnection);
SqlDataAdapter  objDataAdapter=new SqlDataAdapter("select id,count_all from counters",objSqlConnection);
try
  {
string selectCmd="update counters set counte_all=@count where id=1";
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd,objSqlConnection);

myCommand.SelectCommand.Parameters.Add(new SqlParameter("@count", SqlDbType.NVarChar, 2));
myCommand.SelectCommand.Parameters["@count"].Value =100;
   objSqlConnection.Open();
    myCommand.UpdateCommand.ExecuteNonQuery();
.
but i get this error when i run project.
Code:
System.NullReferenceException: Object reference not set to an instance of an object. at WebApplication2.WebForm1.Page_Load(Object sender, EventArgs e) in d:\inetpub\wwwroot\webapplication2\webform1.aspx.cs:line 62System.NullReferenceException
every one to guide me what i must to change to get correct results.
Thanks in Advance.
YoOrD.



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

is this spelled right? counte_all

 
Old August 27th, 2004, 03:33 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

your are right it is not correct and i am change it to correct column name "count_all"
but the error yet persists.
error is:
 
Quote:
quote:System.NullReferenceException: Object reference not set to an instance of an object. at
Quote:
WebApplication2.WebForm1.Page_Load(Object sender, EventArgs e) in
 d:\inetpub\wwwroot\webapplication2\webform1.aspx.c s:line 62System.NullReferenceException

Thanks in Advance.
YoOrD.
Beauty Is not in the face
Beauty is In the heart
--<<Ghibran Khalil>>--
 
Old August 27th, 2004, 03:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

What is line 62?

 
Old August 28th, 2004, 02:38 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

hi stu thank u for your replies
line 62:is this line of code
myCommand.UpdateCommand.ExecuteNonQuery();

but i dont know which intance couldnot be instantiates.
Thanks In Advance .
YoOrD.

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

Leave off 'UpdateCommand' so it reads myCommand.ExecuteNonQuery();

Try that.

 
Old August 31st, 2004, 05:27 PM
shs shs is offline
Authorized User
 
Join Date: Mar 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I am not sure if this is your problem but I think I had this error at some stage in the past when I was trying to display values from database in order to update them.

TO get around it, I had to go to database table and for certain fields which you allow null values, you must set their [u]default value</u>(in design view) to---> (N'-None')
then insert a new row and try to update that new row and see what is the result.





Similar Threads
Thread Thread Starter Forum Replies Last Post
parameterized if-then not working hoqenishy XSLT 1 April 17th, 2008 01:25 PM
Parameterized Property surendraparashar C# 2005 4 October 17th, 2007 11:33 PM
Calling Parameterized Update Query from C# fcortes C# 6 July 11th, 2007 08:47 AM
Parameterized Query asters VB.NET 2002/2003 Basics 5 July 9th, 2007 12:08 PM
Problem In Parameterized ADO.NET Stored Procedure yoord ADO.NET 3 June 19th, 2004 05:09 AM





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