Wednesday 4 November 2015

Create Insert AND Update Form


DataBase Create




Create Insert AND Update Form





using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;

namespace databaseconnection
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnInsert_Click(object sender, EventArgs e)
        {

         string path = "Data Source=.;Initial Catalog=connection;Persist Security Info=True;User ID=sa;Password=123";
         SqlConnection con = new SqlConnection(path);

         SqlCommand cmd = new SqlCommand("insert into Register values ('" + txtName.Text + "', '" + txtEmail.Text + "')", con);
         con.Open();
         cmd.ExecuteNonQuery();

         txtName.Text = "";
         txtEmail.Text = "";
            

            
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string path = "Data Source=.;Initial Catalog=connection;Persist Security Info=True;User ID=sa;Password=123";
            SqlConnection con = new SqlConnection(path);

            SqlCommand cmd = new SqlCommand("UPDATE Register SET Name='" + txtName.Text + "',Email ='" + txtEmail.Text + "' where ID='"+txtUpdate.Text+"'", con);
            con.Open();
            cmd.ExecuteNonQuery();

            txtName.Text = "";
            txtEmail.Text = "";
            
        }
    }

}

No comments:

Post a Comment