1,105,290 Community Members

want to learn insert,update,delete with class file

Member Avatar
patel28rajendra
Newbie Poster
9 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
riteshbest
Light Poster
34 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
Netcode
Veteran Poster
1,049 posts since Jun 2009
Reputation Points: 33 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 8 [?]
 
-2
 

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

Member Avatar
ruchi18
Light Poster
46 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: