Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 9th, 2007, 10:17 PM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default Urgent: Oralce Stored Procedure

Hi,

I never used stored procedures in asp.net and can anyone give example how to create stored procedure in oracle to display users table in grdiview.

Any help highly appreciated.

I wrote something like this, and its giving errors in sql plus.
create or replace PROCEDURE sp_users (out types.cursor)
 AS
CURSOR c1 IS
SELECT * FROM Users
  ;
  rs c1%ROWTYPE;
BEGIN
END;
__________________
Rams
 
Old September 10th, 2007, 05:55 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can simply create like below:

CREATE OR REPLACE PROCEDURE sp_users
IS
BEGIN
  SELECT * FROM Users;
END;

Regards
Mike
===================================
 To the world you might be one person,
 but for someone you may be the whole world.
===================================
^^Though the above is non-technical, but there is no harm thinking emotionally.
 
Old September 14th, 2007, 12:27 PM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mike.. Thank you very much. It works. Now i am stuck with following problem when iam using this with Where statement.

I passed one parameter in that procedure sp_users (sUserFilter as VARCHAR2(64))

In my asp.net code, earlier i was using sql query like this.

sSQL = "SELECT * FROM Users WHERE CreatedOn = to_date('1/1/2007','mm/dd/yyyy') "

If sUserFilter <> "" Then sSQL &= " AND UserID LIKE '%" & sUserFilter & "%'"

Now in stored procedure, how can i write above query, if parameter is null and parameter is not null ?

Any help is great.

Thanks
 
Old September 17th, 2007, 03:51 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

You need to use the Oledb class to access the oracle data, try something like below:

string queryString = "SELECT * FROM Table1 WHERE Field1 LIKE ?";
OleDbCommand command = new OleDbCommand(queryString, connection);
command.Parameters.Add("@p1", OleDbType.Char, 3).Value = "a";
OleDbDataReader reader = command.ExecuteReader();


Regards
Mike
 
Old September 17th, 2007, 02:17 PM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, will this query works even if i don't want to pass parameter? because parameter is not required field.
 
Old September 18th, 2007, 09:55 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

If parameter is not required, do not pass it. I have just given you an example, so modify the sql string accordingly.

Regards
Mike
 
Old September 18th, 2007, 10:06 AM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks.
parameter is required field only when user click on search filter. Do we need to create 2 stored procedures for 2 conditions (with parameter and no parameter)? OR Do we need to change sql query inside sp, if yes how can we?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure muthu555 SQL Server 2000 1 March 5th, 2007 07:13 AM
Stored Procedure Help. midway11 SQL Language 3 November 20th, 2006 06:36 AM
stored procedure keyvanjan Classic ASP Basics 6 August 1st, 2006 07:42 AM
Stored Procedure desireemm SQL Language 5 September 18th, 2004 02:34 AM
stored procedure urgent help required sarfraz Crystal Reports 0 April 19th, 2004 08:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.