Save records in table web applicatiion

Following code in c#  adds a record in table

1. Open visual studio and create a new web project
2. Add a web form in the project
3 The following code is written in web form between form tags
 <div style="width:90%; margin:0 auto">
    <table style=" width:15%; margin: 0 auto">
    <tr>
    <td><asp:Label ID="Label1" runat="server" Text="Name"></asp:Label></td>
    <td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
    <td><asp:Label ID="Label2" runat="server" Text="Mobile"></asp:Label></td>
    <td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
    <td><asp:Label ID="Label3" runat="server" Text="Label" Visible="False"></asp:Label></td>
    <td align="right"><asp:Button ID="Button1" runat="server" Text="Button"
            onclick="Button1_Click" /></td>
    </tr>
    </table>
    </div>
4 Lets create a table in database
You may use the following script to create the table
USE [Databasename]
GO
/****** Object:  Table [dbo].[tbl_sample1]    Script Date: 11/11/2017 2:49:37 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tbl_sample1](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](150) NULL,
[Mobile] [varchar](11) NULL,
 CONSTRAINT [PK_tbl_sample1] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
5 Lets go back to our web application
6 Right click on project name and add new item (see image below)
7 choose data from left pane and LINQ to SQL Classes from items shown(see image below)
8 Once Linq to sql classes is added to the project it will be open now right click on DataConnection
--> Add connection(see image below)
9 If you don't know how to open server explorer where Data connection is listed just go to main menu is visual studio then View--> Server Explorer
10 Just provide credentials to connect to SQL Server(see image below)

11 Now drill down to Tables and drag your table in the designer(see image below)

12 Now lets go back to web form and double click on the button to create its event handler
You may use the following code in .cs file of web form
protected void Button1_Click(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                DataClasses1DataContext db = new DataClasses1DataContext();
                tbl_sample1 smp = new tbl_sample1();
                smp.Name = TextBox1.Text;
                smp.Mobile = TextBox2.Text;
                db.tbl_sample1s.InsertOnSubmit(smp);
                db.SubmitChanges();
                Label3.Visible = true;
                Label3.Text = "Saved";
            }
        }
13 you can now run the application and save the results in database(see image below)

For further question please mail: brainstormiert@gmail.com