Your SlideShare is downloading. ×
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
2310 b 11
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

2310 b 11

413

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
413
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
36
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Module 11: Calling Stored Procedures with Microsoft ADO.NET
  • 2. Overview
    • Overview of Stored Procedures
    • Calling Stored Procedures
  • 3. Lesson: Overview of Stored Procedures
    • What Is a Stored Procedure?
    • Why Use Stored Procedures?
    • Practice: Select the Correct Stored Procedure
  • 4. What Is a Stored Procedure?
    • A common data procedures that can be called by many Web applications
    • Programmatic access to a database
      • Return records
      • Return value
      • Perform action
    Client SQL Server Web Form Stored Procedure Web Server Database
  • 5. Why Use Stored Procedures?
    • Modular programming
    • Distribution of work
    • Database security
    • Faster execution
    • Reduces network traffic
    • Provides flexibility
  • 6. Practice: Select the Correct Stored Procedure
    • Students will:
      • Given scenarios, decide what type of stored procedure needs to be used
    • Time: 5 Minutes
  • 7. Lesson: Calling Stored Procedures
    • Calling Stored Procedures
    • Demonstration: Calling a Stored Procedure
    • Practice: Displaying Data from a Stored Procedure
    • Using Parameters
    • Passing Input Parameters
    • Using Output Parameters
    • Demonstration: Passing Parameters
  • 8. Calling Stored Procedures
    • Identify the stored procedure
    • Set up the SelectCommand property of the DataAdapter
    • Run the stored procedure and store returned records
    Dim daCategory As New SqlDataAdapter() daCategory.SelectCommand = New SqlCommand() daCategory.SelectCommand.Connection = conn daCategory.SelectCommand.CommandText = "ProductCategoryList" daCategory.SelectCommand.CommandType = CommandType.StoredProcedure daCategory.Fill(ds, "Categories") SqlDataAdapter daCategory = new SqlDataAdapter(); daCategory.SelectCommand = new SqlCommand(); daCategory.SelectCommand.Connection = conn; daCategory.SelectCommand.CommandText = "ProductCategoryList"; daCategory.SelectCommand.CommandType = CommandType.StoredProcedure; daCategory.Fill(ds, "Categories");
  • 9. Demonstration: Calling a Stored Procedure
  • 10. Practice: Displaying Data from a Stored Procedure
    • Students will:
      • Drag a stored procedure from Server Explorer onto an ASP.NET Web form
      • Create a DataReader to read data From the stored procedure
      • Bind a DataGrid to the DataReader
    • Time: 15 Minutes
  • 11. Using Parameters
    • Identify the available parameters
      • Input
      • Output
      • InputOutput
      • ReturnValue
    • Include parameters in the parameters collection
    • or
    • Include parameter values in the command string
  • 12. Passing Input Parameters
    • Create parameter, set direction and value, add to the Parameters collection
    • Run stored procedure and store returned records
    SqlParameter param = new SqlParameter ("@Beginning_Date", SqlDbType.DateTime); param.Direction = ParameterDirection.Input; param.Value = Convert.ToDateTime (txtStartDate.Text); da.SelectCommand.Parameters.Add(param); ds = New DataSet(); da.Fill(ds, "Products"); Code Examples ds = New DataSet() da.Fill(ds, "Products") param = New SqlParameter _ ("@Beginning_Date", SQLDbType.DateTime) param.Direction = ParameterDirection.Input param.Value = CDate(txtStartDate.Text) da.SelectCommand.Parameters.Add(param)
  • 13. Using Output Parameters
    • Create parameter, set direction, add to the Parameters collection
    • Run stored procedure and store returned records
    • Read output parameters
    param = New SqlParameter("@ItemCount", SQLDbType.Int) param.Direction = ParameterDirection.Output da.SelectCommand.Parameters.Add(param) ds = new DataSet() da.Fill(ds) iTotal = da.Parameters("@ItemCount").Value param = new SqlParameter("@ItemCount", SqlDbType.Int); param.Direction = ParameterDirection.Output; da.SelectCommand.Parameters.Add(param); ds = new DataSet(); da.Fill(ds); iTotal = da.Parameters("@ItemCount").Value;
  • 14. Demonstration: Passing Parameters
  • 15. Review
    • Overview of Stored Procedures
    • Calling Stored Procedures
  • 16. Lab 11: Calling Stored Procedures with Microsoft ADO.NET Medical Medical.aspx Benefits Home Page Default.aspx Life Insurance Life.aspx Retirement Retirement.aspx Dental Dental.aspx Dentists Doctors Doctors.aspx Doctors Logon Page Login.aspx Registration Register.aspx Coho Winery Prospectus Prospectus.aspx XML Web Service dentalService1.asmx Page Header Header.ascx ASPState tempdb Lab Web Application User Control namedate.ascx Menu Component Class1.vb or Class1.cs XML Files Web. config

×