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

Passing values to Stored Procedure

P: n/a
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;
/* Trying to pass to SP*/

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

SqlConnection connectObj = new SqlConnection(connectionStr);


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)
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


Select Top 0 Locations from SpecialEvents
I get a little lost because a lot of the online tutorials are passing
the values to SqlAdapters!

Jan 5 '07 #1
Share this Question
Share on Google+
1 Reply

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

returnValue.Direction = ParameterDirection.Output;

return (Int64) returnValue.Value;
Jan 5 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.