We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,621 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

want to learn insert,update,delete with class file

plz explain complete step by step procedure to insert update and delete for asp.net2008 with c# and in built sql server.
plz tell me where to make object & class.
I am confused.

5
Contributors
3
Replies
6 Days
Discussion Span
1 Year Ago
Last Updated
5
Views
patel28rajendra
Newbie Poster
9 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

plz explain complete step by step procedure to insert update and delete for asp.net2008 with c# and in built sql server.
plz tell me where to make object & class.
I am confused.

Hi Rajendra,

Always split application, logic, database interaction in different layers for e.g. 3-tier architecture(Presentation - Data Access Layer - Database). So that it is easily maintainable in future.

If you are familiar with C#, you can
> First create a basic layout of ASP.NET application i.e. Design. Be sure what you want on what event.
> Create a database containing your tables, stored procedures and functions if any
> Create a new class library project containing Data Access Logic. In *.cs file you can write C# code.. You can add new item by right click on project and then choose add new item and select Code File.
> Add reference of DAL to ASP.NET application

Syntax: (Insert using query)

public static void insertRecordinDatabase(string query)

        {

            if (establishConnection())

            {

                if (con != null)

                {

                    try

                    {

                        cmd = con.CreateCommand();                 //Create an object of sqlcommand class.

                        cmd.CommandText = query;                  //Pass command text to SqlCommand object.

                        cmd.CommandType = CommandType.Text;      //Tell command type to text.

                        int rows = cmd.ExecuteNonQuery();       //Return an integer value after executing query which represents number of row affected by query.

                        if (rows > 0)

                            Console.WriteLine("Number of rows affected by query  :  {0}", rows);

                        else

                            Console.WriteLine("No rows affected by your query.");

                    }

                    catch

                    {

                        Console.WriteLine("Invalid query.");

                    }

                    finally

                    {

                        if (con != null)

                            con.Close();

                    }

                }

            }


        }

If you want to insert, update delete using SQLDataSource:
http://www.asp.net/data-access/tutorials/inserting-updating-and-deleting-data-with-the-sqldatasource-vb

riteshbest
Light Poster
34 posts since Nov 2009
Reputation Points: 15
Solved Threads: 5
Skill Endorsements: 0

Its simple, just read books. The truth is, not every detail can be explained to you here. We can help when you have difficulties while working

Netcode
Veteran Poster
1,037 posts since Jun 2009
Reputation Points: 43
Solved Threads: 70
Skill Endorsements: 0
ruchi18
Light Poster
46 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0661 seconds using 2.73MB