473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,396 developers and data experts.

Creating SQL Stored Procedures

Hi all,

Here is some information which could help people who want to create stored procedures and execute them in their program.

You can create stored procedures in two ways:
  • Through front end
  • or writing procedure from backend SQLServer.

Back End
First we'll cover how to write a stored procedure in back end.
The following example is how to create a store procedure for MSSql Server:
  • Open enterprise manager,
  • Expand the SQL Server Group,
  • Expand the Server,
  • Select "Databases" folder,
  • Expand the database the store procedure will be written for,
  • Right click "Stored Procedures",
  • Select "New Stored Procedure..."

This will open a dialogue box that will let you create a new Stored Procedure.
In this dialogue box you will enter the commands that will be executed when this store procedure is used.

The following is an example of a store procedure that will add an entry into the "Student" table:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE AddStudent @Sno VARCHAR(10),@Sname VARCHAR(20),@Saddress VARCHAR(50) 
  2.  AS
  3. Begin
  4. INSERT INTO  STUDENT(Sno ,Sname ,Saddress ) values (@Sname ,@Sname,@Saddress)
  5. End
In this example, "AddStudent " is the procedure name and the parameters needed to execute procedure are: "@Sno", "@Sname", "@Saddress". "Sno","Sname","Saddress" are the column names for student table.

Using The Store Procedure In Code
After you create your store procedure in your database, you can use it in your code.

The following is an example of how to store student information into the database (using the store procedure created in the steps above) when the "Savebutton" is clicked.

Expand|Select|Wrap|Line Numbers
  1. Private Sub SaveButton_Click() Handles SaveButton.Click
  2.      Dim conn As SqlConnection = New SqlConnection("data Source=yourserver/systemno;uid="userID";pwd="password";initial catalog=dbname")
  3.      Try
  4.         conn.Open()
  5.         Dim strcmd As SqlCommand = New SqlCommand("stu", conn)
  6.         strcmd.CommandType = CommandType.StoredProcedure
  7.         strcmd.Parameters.Add("@sno", TextBox1.Text)
  8.         strcmd.Parameters.Add("@sname", TextBox2.Text)
  9.         strcmd.Parameters.Add("@saddress", TextBox3.Text)
  10.         strcmd.ExecuteNonQuery()
  11.         conn.Close()
  12.      Catch ex As Exception
  13.  
  14.      End Try
  15.     End Sub
  16. End Class
  17.  
This code will take the values from asp page/form and then stored the values in backend SQLDB.

Hope this will help you.
Jyo!
Apr 20 '07 #1
9 8939
hi ,
ya this is good method to writ stored procedure
Apr 20 '07 #2
hi ,
ya this is good method to writ stored procedure
Thanks! For your comment
Apr 20 '07 #3
Frinavale
9,735 Expert Mod 8TB
Hi jyothi1105!

This is a great post.
Thank you so much for providing us with this resource!

-Frinny
Apr 20 '07 #4
RedSon
5,000 Expert 4TB
Hi jyothi1105!

This is a great post.
Thank you so much for providing us with this resource!

-Frinny
Frin,

Do you want to format this original post a little better and put it in "Frinny's tip o' the week" thread and we can start a sticky thread for all your (and others') tips o' the week?
Apr 20 '07 #5
Frinavale
9,735 Expert Mod 8TB
Frin,

Do you want to format this original post a little better and put it in "Frinny's tip o' the week" thread and we can start a sticky thread for all your (and others') tips o' the week?
This sounds like a great idea!
Apr 20 '07 #6
vidz
2
Great!
Thank you for posting your codes and knowledge. This will help us..
Jan 15 '08 #7
prabur
3
hi
like this stored procedure concepts...
hw can we store the datas into MS ACCESS files...
and hw can we retrive that.. using c#.....
Feb 26 '08 #8
Frinavale
9,735 Expert Mod 8TB
hi
like this stored procedure concepts...
hw can we store the datas into MS ACCESS files...
and hw can we retrive that.. using c#.....
Hi Prabur,

You are going to have to use ADO.NET to connect to your MS Access database files using C#. After you have researched ADO.NET and attempted to solve your problem, please post any question or problems in the .NET forum to receive help.

Cheers!

-Frinny
Feb 26 '08 #9
Really very usefull resource
Mar 2 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Dim St Thomas | last post by:
I am a developer working on a database client program. I am testing this program on a Windows XP machine (1.5 GHz AMD chip, 480 Mb RAM, 60 Gb disk) This machine has Oracle 9.2.0.1.0 and RedBrick...
3
by: Robin Tucker | last post by:
Hi there, I have a database on my test machine that will need to be installed on users machines. I would like to create the database with the given schema on the users machine and also with...
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: billmiami2 | last post by:
Perhaps many of you MS Access fanatics already know this, but it seems that stored procedures and views are possible in Jet. I thought I would leave this message just in case it would help anyone....
5
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
1
by: Cuculain | last post by:
Anyone had problems with this? The Management Studio just saves my attempts to create stored procedures as query files and doesn't add them to the list of stored procedures.
2
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still...
1
by: Quish | last post by:
Hey I am creating a database application that is accessed through a .NET front end. What I want to do is run a SQL script that will create my DB, create my indexes and enforce my constraints...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.