Hi SUJAYS,
Refer below sample.
HTML
Name :
<input type="text" name="txtName" id="txtName" />
<br />
<asp:Button Text="Save" runat="server" OnClick="Save" />
Namespaces
C#
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data.SqlClient
Code
C#
protected void Save(object sender, EventArgs e)
{
string name = Request.Form["txtName"];
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO TestDemo(Name) VALUES(@Name)", con))
{
cmd.Parameters.AddWithValue("@Name", name);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
VB.Net
Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs)
Dim name As String = Request.Form("txtName")
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("INSERT INTO TestDemo(Name) VALUES(@Name)", con)
cmd.Parameters.AddWithValue("@Name", name)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End Sub