By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

help with stored procedure and parameters.

P: n/a
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_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",Session["Locations"]));

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

Jan 8 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
<vn****@hotmail.comwrote in message
news:11**********************@q40g2000cwq.googlegr oups.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_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",Session["Locations"]));

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

Jan 8 '07 #2

P: n/a
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!

Ignacio Machin ( .NET/ C# MVP ) wrote:
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
<vn****@hotmail.comwrote in message
news:11**********************@q40g2000cwq.googlegr oups.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_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",Session["Locations"]));

if( recordreturned == 0 )
{
Server.Transfer("nextpage.aspx");
}
else{
//Stay on the same page!!!!
}
Jan 8 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.