473,398 Members | 2,125 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,398 software developers and data experts.

C#, Stored procedure

30
Hi,
what's is Stored Procedure? Why use?

Maybe have simple example, who send information to SQL DB.


O long use google, bet found many information, and don't now which information is correct. Found examples but all hard. I don't understand.
Jul 25 '08 #1
7 1738
Curtis Rutland
3,256 Expert 2GB
A stored procedure is a procedure created and stored on the database side. It is useful, because you can condense complex and commonly used queries into a single statement. SPs really have nothing to do with C# per se, but with the database. If you choose to store your commonly used queries and procedures as SPs, you can still call them from C#.
Jul 25 '08 #2
Smurfas
30
Thanks ;]

Maybe you now, how like this, whit Stored Procedure

Expand|Select|Wrap|Line Numbers
  1.                  SqlConnection conn;
  2.                 SqlCommand comm;
  3.  
  4.                 String connectionString =
  5.                 ConfigurationManager.ConnectionStrings[
  6.                 "Smurfas"].ConnectionString;
  7.                 conn = new SqlConnection(connectionString);
  8.                 comm = new SqlCommand(
  9.                 "INSERT INTO Bendra (Name,  DataNow) " +
  10.                 "VALUES (@Name, @Data)", conn);
  11.                 //---Nusiunciam duomenis
  12.                 comm.Parameters.Add("@Name",
  13.                 System.Data.SqlDbType.NVarChar, 15);
  14.                 comm.Parameters["@Numeris"].Value = Name;
  15.  
  16.                 comm.Parameters.Add("@Data",
  17.                 System.Data.SqlDbType.NVarChar, 15);
  18.                 comm.Parameters["@Data"].Value = DataNow;
  19.  
  20.                 try
  21.                 {
  22.                     conn.Open();              
  23.                     comm.ExecuteNonQuery();  
  24.  
  25.                 }
  26.                 catch
  27.                 {
  28.                     error.Text = "Error!";
  29.                 }
  30.                 finally
  31.                 {
  32.  
  33.                     conn.Close();  //
  34.                 }
  35.  
Jul 25 '08 #3
Curtis Rutland
3,256 Expert 2GB
Are you asking how to write that query as a SP? You should probably get a tutorial on T-SQL stored procedures.
Jul 25 '08 #4
Smurfas
30
Are you asking how to write that query as a SP? You should probably get a tutorial on T-SQL stored procedures.
"Are you asking how to write that query as a SP? " - Yes
Jul 25 '08 #5
TRScheel
638 Expert 512MB
"Are you asking how to write that query as a SP? " - Yes
How much SQL do you know? Depending on your knowledge will determine where I would start showing you how.
Jul 25 '08 #6
Smurfas
30
How much SQL do you know? Depending on your knowledge will determine where I would start showing you how.
I just need simpla example...

I can put information in DB, get information for DB, update, delete. (without SP)
But about Stored Procedures I don't know near nothing.
Jul 25 '08 #7
TRScheel
638 Expert 512MB
I just need simpla example...

I can put information in DB, get information for DB, update, delete. (without SP)
But about Stored Procedures I don't know near nothing.
Should be something like:
Expand|Select|Wrap|Line Numbers
  1. USE [Sandbox]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[Test]    Script Date: 07/28/2008 10:31:52 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. -- =============================================
  9. -- Author:        Tomas Scheel
  10. -- Create date: July 28th, 2008
  11. -- Description:    Sample Procedure
  12. -- =============================================
  13. CREATE PROCEDURE [dbo].[Test] 
  14.     -- Add the parameters for the stored procedure here
  15.     @Name varchar(50) = '', 
  16.     @Data varchar(50) = ''
  17. AS
  18. BEGIN
  19.     -- SET NOCOUNT ON added to prevent extra result sets from
  20.     -- interfering with SELECT statements.
  21.     SET NOCOUNT ON;
  22.  
  23.     -- Insert statements for procedure here
  24.     Insert into dbo.SandboxTable ([Name], [Data]) values (@Name, @Data)
  25. END
  26.  
For more information take a look at this MSDN link:
MSDN - How to create a stored procedure

I would also suggest downloading Microsoft SQL Server Management Studio Express to play in as it will help you double check your code.
Microsoft SQL Server Management Studio Express
Jul 28 '08 #8

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

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
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...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
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...
3
by: kd | last post by:
Hi All, How to debug a stored procedure? Thanks, kd
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.