Create an asp.net page for new registration and insert record in sql database.

Category > ASP.NET || Published on : Monday, November 23, 2020 || Views: 1056 || insert record in sql database create an asp.net page for new registration page


Here Pawan Kumar will explain how to create an asp.net page for new registration and insert record in sql database.

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DBName;Integrated Security=True;Pooling=False");
    SqlDataAdapter da = new SqlDataAdapter();
    DataSet ds = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string str="insert into Registation values('"+TextBox1 .Text +"','"+TextBox2 .Text +"','"+TextBox3 .Text +"','"+TextBox4 .Text +"','"+TextBox5 .Text +"','"+TextBox6 .Text +"','"+TextBox7 .Text +"')";
        SqlCommand cmd = new SqlCommand(str, con);
        cmd .Connection .Open ();
        cmd .ExecuteNonQuery ();
        cmd .Connection .Close ();
        Response.Write("Record insert");

    }
}