Stored Procedures 2018-11-18.

Slides:



Advertisements
Similar presentations
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
Advertisements

© Logica All rights reserved ADO vNext LINQ LINQ to SQL Entity Framework Freek Leemhuis
ADO. NET. What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
C# 3.0 and LINQ Pavel Yosifovich CTO, Hi-Tech College
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
In C# program Before you can start using the ODBC class definitions, you will need to include the right module. using System.Data.Odbc; // ODBC definitions.
Stored Procedures Dr. Ralph D. Westfall May, 2009.
The OWASP Foundation Injection Flaws.
C# programming with database Basic guideline. First step Install SQL Server 2008/2010 (Professional edition if possible) Install Visual Studio 2008/2010.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
Accessing SQL Server and OLE DB from.NET Svetlin Nakov Telerik Corporation
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
Dinamic SQL & Cursor. Why Dinamic SQL ? Sometimes there is a need to dynamically create a SQL statement on the fly and then run that command. This can.
Stored Procedures, Transactions, and Error-Handling
Neal Stublen Populating a Database  SQLExpress should be installed with Visual Studio  The book provides a.sql file for populating.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
11 Using ADO.NET II Textbook Chapter Getting Started Last class we started a simple example of using ADO.NET operations to access the Addresses.
TOP10 DEV SKILLS TO MAKE YOUR DBA HAPPY Kevin Kline Director of Engineering Services, SQL Sentry SQL Server MVP since 2004 Twitter, FB, LI: KEKline Blog:
OR Mapping Object relational mapping (ORM, O/RM, and O/R mapping)
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
Module 3: Performing Connected Database Operations.
1 11/10/05CS360 Windows Programming ADO.NET. 2 11/10/05CS360 Windows Programming ADO.NET  Behind every great application is a database manager o Amazon.
C# 3.0 and LINQ Pavel Yosifovich CTO, Hi-Tech College
More ASP.NET Database In a properly organized application, your data access code is never embedded directly in the code-behind for a page. Instead, it’s.
Accessing SQL Server and MySQL from.NET and C# Learning & Development Team Telerik Software Academy.
Distributed Database Systems INF413. ADO.NET is a set of classes that comes with the Microsoft.NET framework to facilitate data access from managed languages.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
PHP Database Pemrograman Internet. PHP MySQL Database With PHP, you can connect to and manipulate databases. MySQL is the most popular database system.
CHAPTER 10 PHP MySQL Database
Parametre og variable i T-SQL 1.Parametre (input) 2.Parametre (output) 3.Variable.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
Session 8: Data Management (with Stored Procedures)
Ch 7. Working with relational data. Transactions Group of statements executed as a group. If all statements execute successfully, changes are committed.
Understand Data Definition Language (DDL) Database Administration Fundamentals LESSON 1.4.
.NET Data Access and Manipulation
Module 9: Implementing Functions. Overview Creating and Using Functions Working with Functions Controlling Execution Context.
Creating Functions This presentation was prepared by Professor Steve Ross, with the advice of other MIS Faculty, for use in MIS Classes at Western Washington.
1 c6212 Advanced Database and Client Server MS SQL Server 2000 Stored Procedures and Parameters What ? Why ? How ?
Ten 10 Things DBAs Want.NET Developers to Know Kevin Kline Technical Strategy Manager, Quest
C# MySQL onnect-C-to-MySQL 1.
 ADO.NET is an object-oriented set of libraries that allows you to interact with data sources  Commonly, the data source is a database, but it could.
Web Systems & Technologies
DB Apps Introduction Intro to ADO.NET SQL SoftUni Team DB Apps Intro
ADO.NET and Stored Procedures
How to Create Login Form using vb.net and SqlServer Database
Structured Query Language (SQL)
10 | Programming with Transact-SQL
DataSet и SqlDataAdapter
SQL commands from C# and ASP.net
ADO.Net and Stored Procedures
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Strings A collection of characters taken as a set:
CIS 136 Building Mobile Apps
SQL Code for Byrnetube video
Introduction To Structured Query Language (SQL)
Database Programming By Abdul Hadi M. Alaidi.
SQL Server Stored Procedures.
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
මොඩියුල විශ්ලේෂණය Stored Procedure හඳුන්වා දීම.
COP 2700 – Data Structures (SQL)
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
SQL NOT NULL Constraint
JDBC II IS
SQL (Structured Query Language)
SQL AUTO INCREMENT Field
Presentation transcript:

Stored Procedures 2018-11-18

Stored Procedure – Förarbete CREATE TABLE tbl_Students ( [Studentid] [int] IDENTITY(1,1) NOT NULL, [Firstname] [nvarchar](200) NOT NULL, [Lastname] [nvarchar](200) NULL, [Email] [nvarchar](100) NULL ) Insert into tbl_Students (Firstname, lastname, Email) Values('Vivek', 'Johari', 'vivek@abc.com') Values('Pankaj', 'Kumar', 'pankaj@abc.com') Values('Amit', 'Singh', 'amit@abc.com') Values('Manish', 'Kumar', 'manish@abc.comm')

Hur ser en Stored Procedure ut? Create Procedure Procedure-name ( Input parameters , Output Parameters (If required) ) As Begin Sql statement used in the stored procedure End

Exempel /* GetstudentnameInOutputVariable is the name of the stored procedure which uses output variable @Studentname to collect the student name returns by the stored procedure */ Create PROCEDURE GetstudentnameInOutputVariable ( @studentid INT, -- Input parameter, Studentid of the student @studentname VARCHAR(200) OUT -- Out parameter declared with the help of OUT keyword ) AS BEGIN SELECT @studentname= Firstname+' '+Lastname FROM tbl_Students WHERE studentid=@studentid END

/* This Stored procedure is used to Insert value into the table tbl_students. */ Create Procedure InsertStudentrecord ( @StudentFirstName Varchar(200), @StudentLastName Varchar(200), @StudentEmail Varchar(50) ) As Begin Insert into tbl_Students (Firstname, lastname, Email) Values(@StudentFirstName, @StudentLastName,@StudentEmail) End

Hur ser det ut när vi använder C# string connectionString = @"Server=.\SQLEXPRESS; ” + ”Initial Catalog=SPO12; ” + ”Integrated Security=True;"; SqlConnection conn = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("dbo.GetstudentnameInOutputVariable"); try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@studentid", 1)); SqlParameter nameParameter = new SqlParameter("@studentname", 0); nameParameter.Direction = ParameterDirection.Output; cmd.Parameters.Add(nameParameter); conn.Open(); cmd.Connection = conn;

Hur ser det ut när vi använder C# cmd.ExecuteNonQuery(); string studentName = cmd.Parameters["@studentname"].Value.ToString(); Response.Write("<p>Namnet: " + studentName.ToString()); } Finaly { conn.Close();

Var kan jag finna mera? www.sqlteam.com www.mssqltips.com CodeProject StackOverFlow