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 =
@dotnet.itags.org."server=localhost;uid=user;pwd=pass;trusted_connect ion=true;database=Events";
SqlConnection connectObj = new SqlConnection(connectionStr);
commandObj.Connection.Open();
commandObj.ExecuteNonQuery();
commandObj.Connection.Close();
}
Here is my stored procedure*********************
CREATE PROCEDURE CheckAvailableEvents
@dotnet.itags.org.Yr nvarchar(4)
,@dotnet.itags.org.Mh nvarchar(2)
,@dotnet.itags.org.Dy nvarchar(2)
,@dotnet.itags.org.Locations nvarchar(50)
,@dotnet.itags.org.TotalTimeTo nvarchar(12)
,@dotnet.itags.org.TotalTimeFrom nvarchar(12)
As
IF (SELECT Count(TotalTimeTo) from SpecialEvents Where ((Yr = @dotnet.itags.org.Yr) AND
(Mh = @dotnet.itags.org.Mh) AND (Dy = @dotnet.itags.org.Dy))
AND Locations = @dotnet.itags.org.Locations AND TotalTimeTo = @dotnet.itags.org.TotalTimeTo ) 0
Select Top 1 Locations, TotalTimeTo, ContactPerson, Extension from
SpecialEvents Where ((Yr = @dotnet.itags.org.Yr) AND (Mh = @dotnet.itags.org.Mh) AND (Dy = @dotnet.itags.org.Dy))
AND Locations = @dotnet.itags.org.Locations AND TotalTimeTo = @dotnet.itags.org.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!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;
}
0 comments:
Post a Comment