Stored Procedures and check for recordcount

V

vncntj

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_connection=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
 
K

Karthik D V

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_connection=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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top