Stored Procedures and check for recordcount  
Author Message
tomoseki





PostPosted: Tue Jan 09 21:55:08 CST 2007 Top

Visual C#.Net >> 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"] =3D Locations.Text;


Server.Transfer("AudioVisual.aspx");


/* Calling on Stored Procedure */


string connectionStr =3D
@"server=3Dlocalhost;uid=3D"";pwd=3D"";trusted_connection=3Dtrue;database=
=3DPMAEvents=AD";

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

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

}


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

if( recordreturned =3D=3D 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

DotNet126  
 
 
Karthik





PostPosted: Tue Jan 09 21:55:08 CST 2007 Top

Visual C#.Net >> Stored Procedures and check for recordcount
EMail@HideDomain.com wrote:
> I have this Stored Procedure that is passed the following parameter
>
> protected void btnNext_Click(object sender, EventArgs e)
> {
>
>
> Session["Locations"] =3D Locations.Text;
>
>
> Server.Transfer("AudioVisual.aspx");
>
>
> /* Calling on Stored Procedure */
>
>
> string connectionStr =3D
> @"server=3Dlocalhost;uid=3D"";pwd=3D"";trusted_connection=3Dtrue;database=
=3DPMAEvents=AD";
>
> SqlConnection connectObj =3D new SqlConnection(connectionStr);
> SqlCommand commandObj =3D new SqlCommand("eventtest",
> connectionStr);
> commandObj.CommandType.StoredProcedure;
>
> commandObj.Parameters.Add(new SqlParameter("@Locations",
> SqlDbType.VarChar)).Value =3D Session["Locations"];
>
> }
>
>
> but I'm running into problems when I go to test to see if any values
> were returned
>
> if( recordreturned =3D=3D 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 =3D new SqlConnection();
conn.ConnectionString =3D "Put Connection string here";
SqlCommand cmd =3D new SqlCommand();
cmd.CommandText =3D "Stores Procedure name";
cmd.CommandType =3D CommandType.StoredProcedure;
SqlParameter param =3D new SqlParameter("ParamName",
SqlDbType.Int);
param.Direction =3D ParameterDirection.Input;
//Add some more parameterd , if needed.

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

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

 
 
XOR





PostPosted: Tue Jan 09 22:38:00 CST 2007 Top

Visual C#.Net >> Stored Procedures and check for recordcount
you could use an output parameter in the sql.