473,473 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using stored procedure

I have this syntax working perfectly, but I'm trying to apply a stored
procedure instead using
the CommandText (Sql Statement).

// Open connection to the database
string ConnectionString =
@"server=localhost;uid=;pwd=;trusted_connection=tr ue;database=PMAEvents";

con = new SqlConnection(ConnectionString);
con.Open();
// Set up a command with the given query and associate
// this with the current connection.
string CommandText = "SELECT Locations, EventTitle FROM
specialevents WHERE Locations LIKE @Find";
cmd = new SqlCommand(CommandText);
cmd.Connection = con;
// Add LastName to the above defined parameter @Find
//cmd.Parameters.Add(new SqlParameter("@Find",
System.Data.SqlDbType.NVarChar, "Locations")); // The name of the
source column
cmd.Parameters.Add(new SqlParameter("@Find",
System.Data.SqlDbType.VarChar));
// Fill the parameter with the value retrieved
// from the text field
cmd.Parameters["@Find"].Value = txtFind.Text;
// Execute the query
rdr = cmd.ExecuteReader();

Jan 11 '07 #1
3 1556
I've tried this, (below) but I get 'storedProcCommand' does not exist

// Open connection to the database
string ConnectionString =
@"server=localhost;uid=intranet_content;pwd=conten t;trusted_connection=true;database=PMAEvents";
con = new SqlConnection(ConnectionString);
con.Open();

// Set up a command with the given query and associate
// this with the current connection.

cmd = new SqlCommand("ps_eventtest", con);
storedProcCommand.CommandType =
CommandType.StoredProcedure;
storedProcCommand.Parameters.Add("@Locations",
txtFind.Text);
cmd.Connection = con;

// Add LastName to the above defined parameter @Find
cmd.Parameters.Add(new SqlParameter("@Find",
System.Data.SqlDbType.NVarChar, "Locations")); // The name of the
source column

cmd.Parameters["@Find"].Value = txtFind.Text;

// Execute the query
rdr = cmd.ExecuteReader();

vnc...@hotmail.com wrote:
I have this syntax working perfectly, but I'm trying to apply a stored
procedure instead using
the CommandText (Sql Statement).

// Open connection to the database
string ConnectionString =
@"server=localhost;uid=;pwd=;trusted_connection=tr ue;database=PMAEvents";

con = new SqlConnection(ConnectionString);
con.Open();
// Set up a command with the given query and associate
// this with the current connection.
string CommandText = "SELECT Locations, EventTitle FROM
specialevents WHERE Locations LIKE @Find";
cmd = new SqlCommand(CommandText);
cmd.Connection = con;
// Add LastName to the above defined parameter @Find
//cmd.Parameters.Add(new SqlParameter("@Find",
System.Data.SqlDbType.NVarChar, "Locations")); // The name of the
source column
cmd.Parameters.Add(new SqlParameter("@Find",
System.Data.SqlDbType.VarChar));
// Fill the parameter with the value retrieved
// from the text field
cmd.Parameters["@Find"].Value = txtFind.Text;
// Execute the query
rdr = cmd.ExecuteReader();
Jan 11 '07 #2
Ok! I've got the page working but now I'm not getting any records
returned.

// Open connection to the database
string ConnectionString =
@"server=localhost;uid=intranet_content;pwd=conten t;trusted_connection=true;database=PMAEvents";
con = new SqlConnection(ConnectionString);
con.Open();

// Set up a command with the given query and associate
// this with the current connection.

cmd = new SqlCommand("ps_eventtest", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Locations", txtFind.Text);
cmd.Connection = con;

// Add LastName to the above defined parameter @Find
cmd.Parameters.Add(new SqlParameter("@Find",
System.Data.SqlDbType.NVarChar)); // The name of the source column

cmd.Parameters["@Find"].Value = txtFind.Text;

// Execute the query
rdr = cmd.ExecuteReader();

vnc...@hotmail.com wrote:
I've tried this, (below) but I get 'storedProcCommand' does not exist

// Open connection to the database
string ConnectionString =
@"server=localhost;uid=intranet_content;pwd=conten t;trusted_connection=true;database=PMAEvents";
con = new SqlConnection(ConnectionString);
con.Open();

// Set up a command with the given query and associate
// this with the current connection.

cmd = new SqlCommand("ps_eventtest", con);
storedProcCommand.CommandType =
CommandType.StoredProcedure;
storedProcCommand.Parameters.Add("@Locations",
txtFind.Text);
cmd.Connection = con;

// Add LastName to the above defined parameter @Find
cmd.Parameters.Add(new SqlParameter("@Find",
System.Data.SqlDbType.NVarChar, "Locations")); // The name of the
source column

cmd.Parameters["@Find"].Value = txtFind.Text;

// Execute the query
rdr = cmd.ExecuteReader();

vnc...@hotmail.com wrote:
I have this syntax working perfectly, but I'm trying to apply a stored
procedure instead using
the CommandText (Sql Statement).

// Open connection to the database
string ConnectionString =
@"server=localhost;uid=;pwd=;trusted_connection=tr ue;database=PMAEvents";

con = new SqlConnection(ConnectionString);
con.Open();
// Set up a command with the given query and associate
// this with the current connection.
string CommandText = "SELECT Locations, EventTitle FROM
specialevents WHERE Locations LIKE @Find";
cmd = new SqlCommand(CommandText);
cmd.Connection = con;
// Add LastName to the above defined parameter @Find
//cmd.Parameters.Add(new SqlParameter("@Find",
System.Data.SqlDbType.NVarChar, "Locations")); // The name of the
source column
cmd.Parameters.Add(new SqlParameter("@Find",
System.Data.SqlDbType.VarChar));
// Fill the parameter with the value retrieved
// from the text field
cmd.Parameters["@Find"].Value = txtFind.Text;
// Execute the query
rdr = cmd.ExecuteReader();
Jan 11 '07 #3

vnc...@hotmail.com wrote:
I've tried this, (below) but I get 'storedProcCommand' does not exist
cmd = new SqlCommand("ps_eventtest", con);
storedProcCommand.CommandType = CommandType.StoredProcedure;
storedProcCommand.Parameters.Add("@Locations", txtFind.Text);
That's because storedProcCommand has not been defined anywhere, and
also the parameter adding syntax appears to be incorrect.

Assuming you have 'cmd' defined elsewhere as a SqlCommand object, you
can change the second and third of the above lines to read as follows:

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Locations", txtFind.Text));

The following article is a good demonstration of the techniques
involved here.

http://www.codeproject.com/cs/database/albumviewer.asp

Jan 11 '07 #4

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

Similar topics

0
by: Aaron | last post by:
The following code works fine when previewing a Crystal report using ASP, EXCEPT when it gets to a report using a SubReport and its associated parameters. The whole report just comes up blank with...
5
by: Warren Wright | last post by:
Hi group, I have a select statement that if run against a 1 million record database directly in query analyzer takes less than 1 second. However, if I execute the select statement in a stored...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
4
by: marc | last post by:
I've been developing a stored procedure that uses a user defined function in the query portion of the procedure. However, since the end product needs to allow for dynamic table names, the UDF will...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
1
by: deepdata | last post by:
Hi, I am trying to fetch data from db2 (express version) database by calling stored procedure. I have tried to use both cursor and for loop but still i am getting error. --======Start...
1
by: ILCSP | last post by:
Hello, I'm trying to accomplish 3 things with one stored procedure. I'm trying to search for a record in table X, use the outcome of that search to insert another record in table Y and then exec...
2
by: acw | last post by:
On a SQL Server 2000 db I would like to setup a stored procedure that accesses couple tables and runs the extended stored procedure xp..cmdshell. The goal is to grant users with limited privileges...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.