473,383 Members | 1,862 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,383 software developers and data experts.

display an alert depending value returned by @@rowcount from stored procedure

20
I'm using ASP.net2.0,SQLserver2005.i have a stored procedure which returns the number of rows affected by a search based on search key.i want that if no rows are returned,an alert box with custom message should appear.

When i run the code below, i get an error


Error 2 Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?)



Expand|Select|Wrap|Line Numbers
  1. protected void btnSearch_Click(object sender, EventArgs e)
  2.     {
  3.         string constring = ConfigurationManager.AppSettings.Get("con").ToString();
  4.         SqlConnection conn = new SqlConnection(constring);
  5.         conn.Open();
  6.  
  7.         SqlCommand check = new SqlCommand("spSearchCombo", conn);
  8.         check.CommandType = CommandType.StoredProcedure;
  9.  
  10.  
  11.         check.Parameters.Add(new SqlParameter("@searchBy", SqlDbType.NVarChar, 50));
  12.         check.Parameters["@searchBy"].Value = ddlSearchBy.SelectedItem.Value.ToString();
  13.  
  14.  
  15.         check.Parameters.Add(new SqlParameter("@searchKey", SqlDbType.NVarChar, 50));
  16.         check.Parameters["@searchKey"].Value = txtSearch.Text;
  17.  
  18. //@no_rows=@@rowcount in stored procedure
  19.  
  20.         check.Parameters.Add(new SqlParameter("@no_rows",SqlDbType.Int));
  21.         check.Parameters["@no_rows"].Direction = ParameterDirection.Output;
  22.  
  23.         int result = check.Parameters["@no_rows"].Value;
  24.  
  25.         if (result >0)
  26.        {
  27.             SqlDataAdapter da = new SqlDataAdapter(check);
  28.             DataSet ds = new DataSet();
  29.             da.Fill(ds);
  30.             this.dgv1.DataSource = ds.Tables[0].DefaultView;
  31.  
  32.             dgv1.DataBind();
  33.  
  34.             conn.Close();
  35.        }
  36.  
  37.         else
  38.         {
  39.             Response.Redirect("<script language='javascript'>alert('No record  matches your criteria');</script>");
  40.         }
  41.  
  42.     }
  43.  
  44.  
when i change the code to

check.Parameters["@no_rows"].Direction = ParameterDirection.Output;

string result = check.Parameters["@no_rows"].Value.ToString();

if (result !="0")
followed by data adapter code i get
Object reference not set to an instance of an object. at run time

Plz help me out.plz guide me as to how them 'check' command can be used inside 'if' block to implement my need.

Thanking u in advance
Sep 9 '10 #1
1 1925
mzmishra
390 Expert 256MB
Couple of things I observe
1.You are missing execute statement before
int result = check.Parameters["@no_rows"].Value;
also u can check
if(check.Parameters["@no_rows"].Value!=DBNull.Value)
Sep 9 '10 #2

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

Similar topics

3
by: michelle | last post by:
I am trying to get an output value from a stored procedure using sqlDataSource in asp.net 2.0. But I only get a null value for the output. Can someone please help? The sqlDataSource: ...
2
by: Godzilla | last post by:
Dear all, I have a challenge in hand and am not too sure how to accomplish this using stored procedure. I have a table containing about 3 fields, but I need to reorder/renumber a field value...
0
by: skchonghk | last post by:
Dear Experts, In a table UDF, do you know how to open cursor to the resultset returned by stored procedure? Thanks!!!
1
by: endriu | last post by:
Hi I want to recive some data from db2 (as400) using ado.net in visual basic. Also i want to access them by stored procedure that return a cursor. So, i create very simple stored procedure on...
1
by: CSINVA | last post by:
I have a stored procedure that returns columns from a table called UserProfile. Within the table, it has a column called ProfielD, PropertyValue, Visitbility. I need to be able set the values...
5
by: CyberSoftHari | last post by:
I am trying to get an output Parameters value from a stored procedure using sqlDataSource in asp.net 2.0. But I only get a null value for the output Parameters. Can someone Point me to get value? ...
2
by: gopi2ks | last post by:
I have one stored procedure like sp_insertEmployee Employee Table Fileds Eno int pk, ename varchar(100), designation varchar In stored Procedure After inserting the ename and...
1
by: psycho | last post by:
How do we return a single value from a stored procedure. Suppose I have a stored procedure like this: create proc dbo.spInsertGroup @ID uniqueidentifier @GroupName varchar(100), @IsActive...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.