473,385 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Passing values to Stored Procedure

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_conne ction=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!

Jan 5 '07 #1
1 2090
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;
}
Jan 5 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
2
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
10
by: Resant | last post by:
I have a query : Exec 'Select * From Receiving Where Code In (' + @pCode + ')' @pCode will contain more than one string parameter, eg : A1, A2, A3 How can i write that parameters, I try use :...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
15
by: Steve | last post by:
I am trying to develop a stored procedure for an existing application that has data stored in numerous tables, each with the same set of columns. The main columns are Time and Value. There are...
9
by: anilcool | last post by:
Hi all, Another novice question. I want to insert multiple records into my DB2 database using stored procedure but I do not know how many I would like to insert at any given time. Each record...
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx...
1
by: chariclark | last post by:
This may be a quick fix post... ---------------------------- I am having trouble passing multiple values into stored procedure. Here it is below: CREATE Procedure spGetAssociateds ( @PDSI...
1
by: udaypawar | last post by:
Hi All, I have one problem here with mysql stored procedures. I have a list of ids seperated by comma e.g., (" 'A', 'B', 'C' "). I am passing the same to mysql stored procedure as a parameter....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.