473,387 Members | 1,464 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.

Stored Procedures and check for recordcount

I have this Stored Procedure that is passed the following parameter

protected void btnNext_Click(object sender, EventArgs e)
{
Session["Locations"] = Locations.Text;
Server.Transfer("AudioVisual.aspx");
/* Calling on Stored Procedure */
string connectionStr =
@"server=localhost;uid="";pwd="";trusted_connectio n=true;database=PMAEvents*";

SqlConnection connectObj = new SqlConnection(connectionStr);
SqlCommand commandObj = new SqlCommand("eventtest",
connectionStr);
commandObj.CommandType.StoredProcedure;

commandObj.Parameters.Add(new SqlParameter("@Locations",
SqlDbType.VarChar)).Value = Session["Locations"];

}
but I'm running into problems when I go to test to see if any values
were returned

if( recordreturned == 0 )
{
Server.Transfer("nextpage.aspx");
}
else{
//Stay on the same page!!!!
}

i'm a little stuck on the syntax to test if the sp returned any
records!

thanks

Jan 9 '07 #1
2 1712

vnc...@hotmail.com wrote:
I have this Stored Procedure that is passed the following parameter

protected void btnNext_Click(object sender, EventArgs e)
{
Session["Locations"] = Locations.Text;
Server.Transfer("AudioVisual.aspx");
/* Calling on Stored Procedure */
string connectionStr =
@"server=localhost;uid="";pwd="";trusted_connectio n=true;database=PMAEvents*";

SqlConnection connectObj = new SqlConnection(connectionStr);
SqlCommand commandObj = new SqlCommand("eventtest",
connectionStr);
commandObj.CommandType.StoredProcedure;

commandObj.Parameters.Add(new SqlParameter("@Locations",
SqlDbType.VarChar)).Value = Session["Locations"];

}
but I'm running into problems when I go to test to see if any values
were returned

if( recordreturned == 0 )
{
Server.Transfer("nextpage.aspx");
}
else{
//Stay on the same page!!!!
}

i'm a little stuck on the syntax to test if the sp returned any
records!

thanks
Hi,

This is how you can do i feel... I have given some code snippet.

SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Put Connection string here";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Stores Procedure name";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter("ParamName",
SqlDbType.Int);
param.Direction = ParameterDirection.Input;
//Add some more parameterd , if needed.

// Assign the return paramter.
SqlParameter retValue = new SqlParameter("@RETUTRN_VALUE",
SqlDbType.Int);
retValue.Direction = ParameterDirection.ReturnValue;
cmd.ExecuteScalar();
// Get the return value here.
int returnValue = Convert.ToInt32(retValue.Value);

//Another way of getting return value.
returnValue = cmd.ExecuteNonQuery(); //This will return
only in case of insert, delete , update command.

Jan 10 '07 #2

you could use an output parameter in the sql.
Jan 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Racer-D | last post by:
When some of the SQL Server stored procedures I have written are called via my Classic ASP page I have written I get the following error in the cell that is supposed to be retrieving a single...
1
by: Mike Brown | last post by:
What methods are people using out there to keep their stored procedures under CM control? We are using CVS for our CM system. Looking for an easy way to get stored procedures scripted out as text...
17
by: serge | last post by:
How can i delete all user stored procedures and all table triggers very fast in a single database? Thank you
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
1
by: Alex | last post by:
Hi all, Just been dabbling with java stored procedures and I'm having problems replacing System: db2 8.1.4 on RH 7.1 linux system 1). Look at java jdbc samples as supplied with db2 and run...
0
by: billmiami2 | last post by:
Perhaps many of you MS Access fanatics already know this, but it seems that stored procedures and views are possible in Jet. I thought I would leave this message just in case it would help anyone....
5
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
10
by: Dick | last post by:
Using Visual Studio 2003 you were able to manage SQL stored procedures with Visual Source Safe. So long as Visual Studio was used as the editor, it was imposible to make a change to a stored...
2
by: pascal.baetscher | last post by:
Hello everyone, I face currently a problem where I could need some input for searching the source of the Problem System: SQL Server 9.0 I fill from Database A with triggers Database B,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.