Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Nikolaos Kantzelis ASP.Net Blog

This blog will focus on ASP.NET Framework

  • ASP.NET 4.0 and ClientID Mode

    In this post I will be talking about a new enhancement in ASP.NET 4.0.It is now possible to set the name of your controls ClientID attribute, thanks to the ClientIDMode property. Developers requested a better way of setting names of the web server controls and with the new version of ASP.NET 4.0, this is now a reality.

  • Stored procedures with Linq to Sql in an ASP.Net application


    First we need to create the 3 stored procedures that will insert,update and delete records from the Authors table

    This is not a post on how to create stored procedures, so i am just going to paste here the complete stored procs.

       
          DeleteAuthor

    USE [pubs]
    GO

    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    CREATE PROCEDURE [dbo].[DeleteAuthor]

    @AuthorID nvarchar(20)

    AS
    BEGIN

    DELETE FROM authors
    WHERE au_id = @AuthorID

    END
    GO


       
          UpdateAuthor

    USE [pubs]
    GO

    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    CREATE PROCEDURE [dbo].[UpdateAuthor]

    @authorID varchar(11),
    @lname nvarchar(50),
    @fname nvarchar(50),
    @phone char(12),
    @address nvarchar(40),
    @city nvarchar(40),
    @state char(2),
    @zip char(5),
    @contract bit

    AS
    BEGIN

    UPDATE authors
    SET

    au_lname=@lname,
    au_fname=@fname,
    phone=@phone,
    address=@address,
    city=@city,
    state=@state,
    zip=@zip,
    contract=@contract
    WHERE au_id  = @authorID

    END
    GO


       
          InsertAuthor

    USE [pubs]
    GO

    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    CREATE PROCEDURE [dbo].[InsertAuthor]
    @id varchar(11),
    @lName nvarchar(50),
    @fname nvarchar(50),
    @phone char(12),
    @address nvarchar(40),
    @city nvarchar(40),
    @state char(2),
    @zip char(5),
    @contract bit

    AS
    BEGIN

    INSERT INTO pubs.dbo.authors(
    au_id,
    au_lname,
    au_fname,
    phone,
    address,
    city,
    state,
    zip,
    contract)
    VALUES (
    @id,
    @lname,
    @fname,
    @phone,
    @address,
    @city,
    @state,
    @zip,
    @contract)

    END


    GO

    1) Launch Visual Studio 2008

    2) Create an ASP.net web application. Use C# a your language of development

    3) Name your project – solution as you want.

    4) Open the Server Explorer and connect to the Pubs database.

    5) Add a new item in your project, a Linq to SQL classes, a .dbml file. name it authors.dbml

    6) Drag and drop from the Server explorer window the authors table into the designer area (on the .dbml file)

    7) Right-Click on the designer area and show the “Show methods Pane”

    8) Drag and drop the stored procedures from the Server explorer to the designer area

    9) Select the author entity from the deisgner area and select the Properties window. In theDefault methods we need to assign the correct stored procs and not to leave the default option which is “use Runtime”. So please assign the different methods to their respective stored procs. Have a look at the picture below



    10) We will use these stored procs that are methods now as far as LINQ is concerned to update,insert and delete records from the database.

    11) Add a button in the Default.aspx file. Name it “Update”.Double click on this button. In the event handling routine type: