Passing values to Stored Procedure

V

vncntj

I have a C#.NET that simply passes 6 values to a Stored Procedure. But
I'm trying to get the (Default.aspx.cs page) to handle passing the
values to the sp. The goal is to pass the values and see if any
records are returned. I will later insert some conditional statements.

Here is my Default.aspx.cs

protected void btnNext_Click(object sender, EventArgs e)
{

Session["TotalTimeTo"] = TotalTimeTo.Text;
Session["TotalTimeFrom"] = TotalTimeFrom.Text;
Session["Locations"] = Locations.Text;

Session["Mh"] = Mh.Text;
Session["Dy"] = Dy.Text;
Session["Yr"] = Yr.Text;
Server.Transfer("page3.aspx");
/* Trying to pass to SP*/

string connectionStr =
@"server=localhost;uid=user;pwd=pass;trusted_connection=true;database=Events";

SqlConnection connectObj = new SqlConnection(connectionStr);

commandObj.Connection.Open();
commandObj.ExecuteNonQuery();
commandObj.Connection.Close();
}

Here is my stored procedure*********************

CREATE PROCEDURE CheckAvailableEvents
@Yr nvarchar(4)
,@Mh nvarchar(2)
,@Dy nvarchar(2)
,@Locations nvarchar(50)
,@TotalTimeTo nvarchar(12)
,@TotalTimeFrom nvarchar(12)
As
IF (SELECT Count(TotalTimeTo) from SpecialEvents Where ((Yr = @Yr) AND
(Mh = @Mh) AND (Dy = @Dy))
AND Locations = @Locations AND TotalTimeTo = @TotalTimeTo ) > 0

Select Top 1 Locations, TotalTimeTo, ContactPerson, Extension from
SpecialEvents Where ((Yr = @Yr) AND (Mh = @Mh) AND (Dy = @Dy))
AND Locations = @Locations AND TotalTimeTo = @TotalTimeTo

ELSE

Select Top 0 Locations from SpecialEvents


I get a little lost because a lot of the online tutorials are passing
the values to SqlAdapters!
 
K

Keith Patrick

Try this. It uses "using" to implicitly clean up all your DB stuff when
disposed:
using (SqlCommand command = new SqlCommand(new SqlConnection(...)))
{
command.Parameters.Add("@Param1", param1);
command.Parameters.Add("@Param2", param2);
SqlParameter returnValue = new SqlParameter("@Identity",
SqlDbType.BigInt);

returnValue.Direction = ParameterDirection.Output;
command.Parameters.Add(returnValue);
command.ExecuteNonQuery();

return (Int64) returnValue.Value;
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top