help with stored procedure and parameters.

V

vncntj

I'm trying to passing the Session["Locations"] value back to the store
procedure, but I'm having difficulty understanding stored procedures
and parameters. What I'm trying to accomplish is to have the Session
variable passed through as a parameter to the Stored Procedure where I
can test to see if any records exist? if no record exist then we can
move to the next page.

thanks,


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",Session["Locations"]));

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

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You should read the docs, the code below most probably will not compile.
This line is wrong
commandObj.Parameters.Add(new
SqlParameter("@Locations",Session["Locations"]));

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

vncntj

Thanks,

Where I'm a little lost (on the syntax) is how to test to see if any
records were returned. I wanted to test this inside of the

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

thanks!
Hi,

You should read the docs, the code below most probably will not compile.
This line is wrong
commandObj.Parameters.Add(new
SqlParameter("@Locations",Session["Locations"]));

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



--
Ignacio Machin
machin AT laceupsolutions com


I'm trying to passing the Session["Locations"] value back to the store
procedure, but I'm having difficulty understanding stored procedures
and parameters. What I'm trying to accomplish is to have the Session
variable passed through as a parameter to the Stored Procedure where I
can test to see if any records exist? if no record exist then we can
move to the next page.

thanks,


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",Session["Locations"]));

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

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