Here i have explained how to Insert Data into Database in Asp.Net C#.

Step 1) Add HTML:

<div>     
<table> 
<tr> 
<td> <div> First Name</div> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div> <asp:RequiredFieldValidator ValidationGroup="Addrows"  ID="RequiredFieldValidator1" runat="server" ErrorMessage="First Name Required" ControlToValidate="TextBox1"></asp:RequiredFieldValidator> </td>
<td width="2"> </td>
<td><div> Last Name</div> <div> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></div><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Last Name Required" ValidationGroup="Addrows"  ControlToValidate="TextBox2"></asp:RequiredFieldValidator>   </td>
<td width="2"> </td>   
<td><div> Country</div> <div> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></div> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Country Required" ValidationGroup="Addrows"  ControlToValidate="TextBox3"></asp:RequiredFieldValidator></td>
<td width="2"> </td>
<td><asp:Button CssClass="btn bg-primary btn-lg" ID="btnSave" runat="server" Text="Save" ValidationGroup="Addrows" OnClick="btnSave_Click" /> </td>
</tr>
</table>
</div>
<div> <asp:Label runat="server" ID="MsgSuccess" ForeColor="Green"> </asp:Label> </div>

Step 2) Import Namespaces

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

Step 3) C#

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ BindUserDetails(); 
}
}
protected void BindUserDetails() { }   
protected void btnSave_Click(object sender, EventArgs e)
{      
//connectionStrings
String ConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(ConnString);
   
//insert data
SqlCommand cmd = new SqlCommand("insert into table_name (firstName,lastName,Country) values(@firstName,@lastName,@Country)", con);
con.Open();
cmd.Parameters.AddWithValue("@firstName", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@lastName", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@Country", TextBox3.Text.Trim());
cmd.ExecuteNonQuery();
con.Close();
MsgSuccess.Text = "Data Inserted Succesfully";
BindUserDetails();
//clear fields 
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";

}

Screenshot

Add Comments