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

August 27th, 2004, 02:08 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
You need to execute the query.
objSqlConnection.Open();
myCommand.ExecuteNonQuery();
objSqlConnection.Close();
|

August 27th, 2004, 02:14 PM
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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>>--
|

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

August 27th, 2004, 03:17 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
is this spelled right? counte_all
|

August 27th, 2004, 03:33 PM
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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>>--
|

August 27th, 2004, 03:50 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
What is line 62?
|

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

August 30th, 2004, 07:25 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Leave off 'UpdateCommand' so it reads myCommand.ExecuteNonQuery();
Try that.
|

August 31st, 2004, 05:27 PM
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |