.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 11th, 2004, 03:21 AM
seaview seaview is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 14 seaview User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb How to get return value from sql ExecuteNonQuery

Hi,

Anyone know how to get the return value (number of rows affrected) from update query below? Below is the way i did to execute the command in vb.net, but i'm not sure how to check for return value. Please help.

========

Public Sub CreateMySqlCommand(myExecuteQuery As String, myConnection As SqlConnection)
Dim myCommand As New SqlCommand(myExecuteQuery, myConnection)
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub 'CreateMySqlCommand

========

Thank you

Reply With Quote
  #2  
Old April 12th, 2004, 02:02 AM
harikishore harikishore is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Bangalore
Posts: 5 harikishore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,
If your command is Insert, Update or Delete, executeNonquery returns an integer specifying the number of rows affected. Get it in an integer variable.

-Kishore.

Reply With Quote
  #3  
Old April 12th, 2004, 12:14 PM
StudioReview StudioReview is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 30 StudioReview User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Yep, just like Kishore said:


Public Sub CreateMySqlCommand(myExecuteQuery As String, myConnection As SqlConnection)
Dim myCommand As New SqlCommand(myExecuteQuery, myConnection)
Dim rowsAffected as integer
myCommand.Connection.Open()
rowsAffected = myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub 'CreateMySqlCommand
__________________
Tivo Codes, Hacking the Tivo, and Adding a Second Drive to Your Tivo.
All this information at www.TivoSpy.com !

Reply With Quote
  #4  
Old April 12th, 2004, 10:01 PM
seaview seaview is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 14 seaview User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Kishore and StudioReview,

First of all, thanks for your reply. Yep, i did try this method but the value i get is always 0 no matter how many rows are affected. Any idea? Well, perhaps i should check my code again.

Reply With Quote
  #5  
Old April 13th, 2004, 02:31 AM
seaview seaview is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 14 seaview User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

Kishore and StudioReview,

I managed to get the correct return value now. Thanks again for your help. It works!

Regards, Seaview

Reply With Quote
  #6  
Old September 11th, 2005, 04:38 PM
nicelyc nicelyc is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 1 nicelyc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 24 sec
Reputation Power: 0
Solution?

seaview:

In addition to thanking those who lent their assistance, it is often helpful for you to indicate *how* you solved your original problem.

This helps those of us who search forums long after your problem is solved, and is consistent with the spirit of community developer support.

I was having the same problem that you were, and realized that my stored procedure definition began with SET NOCOUNT ON and ended with SET NOCOUNT OFF.

This was preventing the number of affected rows from being returned by Command.ExecuteNonQuery().

Hopefully, this information will help the next person who falls victim to the same oversight.

Thanks!

Quote:
Originally Posted by seaview
Kishore and StudioReview,

I managed to get the correct return value now. Thanks again for your help. It works!

Regards, Seaview

Reply With Quote
  #7  
Old June 5th, 2007, 10:34 AM
pbd22 pbd22 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 9 pbd22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 56 sec
Reputation Power: 0
thanks!

it seems i was the next victim.
the "no count" advice helped!

Reply With Quote
  #8  
Old February 13th, 2009, 04:26 AM
gilsygirl gilsygirl is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 1 gilsygirl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 39 sec
Reputation Power: 0
Stored Procedures

HELLO everyone

I am developing my first vb.net window application. I have a stored procedure that is excueted when i click on the add buttom to save date into my sql 2005 database.

But the problem is i have this error message ('Error Message *Procedure or function Sp_CandSubject has too many arguments specified.

In my table i have field that may have null values but even if i supply all fields with values t give the same error message.
Does anyone Have an idea. i

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > How to get return value from sql ExecuteNonQuery


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap