473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Prblem in getting the rows affected values in sqlserver to C# class.

hi all
i have c# class which calls a stored procedure having insert,update and delete method (using if to switch between them).

when i call the SP to EXECUTENONQUER() there is no response from the sqlserver. I too tested the stored proc seperately , it shows NO ROWS AFFECTED and 0 ROWS RETURNED. But the rows get inserted , or updated according to my call.(i found this by checking recs in table).what would be the trouble?? really confusing me.

below is my stored proc .
C# connectivity code:
Expand|Select|Wrap|Line Numbers
  1. sqlCon = new SqlConnection(strCon);
  2. sqlCmd = new SqlCommand();
  3. sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
  4. sqlCmd.CommandText = "[SP Name]";
  5. sqlCmd.Connection = sqlCon;
  6. if (sqlCon.State == ConnectionState.Closed)
  7. sqlCon.Open();
  8. int result = sqlCmd.ExecuteNonQuery();
  9.  
stored procedure
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE SP_insertUserMaster
  2.     (
  3.     @UserName nvarchar(30),
  4.     @LoginId nvarchar(50),
  5.     @Password nvarchar(80),
  6.     @SecurityLevel int,
  7.     @Department    nvarchar(15),
  8.     @TP nchar(1))
  9.  
  10. AS
  11.      SET NOCOUNT ON 
  12.      if @TP='I'
  13.         BEGIN    
  14.             DECLARE @nCnt NUMERIC
  15.             SELECT @nCnt=(select count(*) from UserMaster Where LoginId=@LoginId)
  16.             IF @nCnt<=0
  17.             begin
  18.                     INSERT INTO UserMaster
  19.                     (UserName, LoginId, Password, SecurityLevel, Department)
  20.                      VALUES
  21.                     (@UserName,@LoginId,@Password,@SecurityLevel,@Department)    
  22.             end
  23.  
  24.         END
  25. return
  26.  
  27.  
  28. thanku
  29.  
  30.  
  31.  
Jan 10 '08 #1
3 3016
ck9663
2,878 Expert 2GB
use @@rowcount

-- CK
Jan 10 '08 #2
hi ck
i am new to sqlserver, can u tell in detail to rectify my trouble.

thank u

ssk
Jan 10 '08 #3
ck9663
2,878 Expert 2GB
hi ck
i am new to sqlserver, can u tell in detail to rectify my trouble.

thank u

ssk

am not sure how c# works. but in ASP, you can execute stored proc and can return resultset. the following query can work in ASP. try it in c#. test it first.


Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE SP_insertUserMaster
  2.     (
  3.     @UserName nvarchar(30),
  4.     @LoginId nvarchar(50),
  5.     @Password nvarchar(80),
  6.     @SecurityLevel int,
  7.     @Department nvarchar(15),
  8.     @TP nchar(1))
  9.  
  10. AS
  11.      SET NOCOUNT ON
  12.      if @TP='I'
  13.         BEGIN   
  14.             DECLARE @rCnt int
  15.  
  16.             if not exists(select 1 from UserMaster Where LoginId=@LoginId)
  17.             begin
  18.                     INSERT INTO UserMaster
  19.                     (UserName, LoginId, Password, SecurityLevel, Department)
  20.                      VALUES
  21.                     (@UserName,@LoginId,@Password,@SecurityLevel,@Department) 
  22.  
  23.                     select @@rowcount
  24.                     return1/9/2008
  25.             end
  26.  
  27.         END
  28.  
  29.  
also, this will only return value if the loginid is not yet in usermaster.try passing a loginid that you know not existing yet...

-- CK
Jan 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: RotterdamStudents | last post by:
Hello there, i have a strange problem. I can't get php to insert multiple rows at once in a MySQL database. I use the $sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d',...
3
by: Savas Ates | last post by:
My Stored ********************************************************* CREATE PROCEDURE st_seconddegree @fromwhom numeric(18), @towhom numeric(18) AS if not exists (select 1 from crosstable where...
2
by: Gnurp Gnarp | last post by:
When the number of columns get large, it becomes increasingly difficult to view the results of a select in a small window (e.g. 80 line xterm) because of line wrapping. Can I have the results of...
1
by: dkode8 | last post by:
Heres my problem, the first part selects a row from the database, if there is no row with the criteria it inserts a row and then returns it, the problem is the IF statement that inserts the row,...
8
by: manning_news | last post by:
Using SQL2000. According to Books Online, the avg aggregrate function ignores null values. ((3+3+3+3+Null)/5) predictably returns Null. Is there a function to ignore the Null entry, adjust the...
4
by: Richard G | last post by:
I'm a database guy, so go easy on me here. :) How can I get the rowcount of the affected rows of a SQL statement from a stored procedure call? I know that "set nocount on" does not return the...
4
by: kenfar | last post by:
I've got a batch etl process in which I typically wrap DML with selects in order to capture the number of rows affected. For example: SELECT 'rows updated', COUNT(*) FROM NEW TABLE ( UPDATE...
2
by: Dave | last post by:
I'm in need of a little sql help. How do i get a list of ids from one table that do not have the same ids in another table? I hope that makes sense.
0
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.