1.subject: Insert Countrey Base State

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

1.

SUBJECT: INSERT COUNTREY BASE STATE


using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default4 : System.Web.UI.Page
{
int a;
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["vy"].ToString());
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from COUNTRY ";
adp.SelectCommand = cmd;
adp.Fill(dt);
DropDownList1.DataValueField = "cid";

DropDownList1.DataTextField = "cname";
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "-select-");
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "insert into state1 values('" + TextBox1.Text + "'," +DropDownList1.SelectedValue +")";
cmd.ExecuteNonQuery();
con.Close();
}
}
SUBJECT: SQL QUERY OF COUNTRY

create table country (cid int primary key,cname varchar(50))


create table state (sid int primary key,sname varchar(50),cid int foreign key references country)
create table district (dname varchar(50),sid int foreign key references state)

insert into country values(12,'US')


insert into state values(106,'US2',12)
insert into district values('U12',106)

select * from district


select * from state
select * from country

SUBJECT: COUNTRY-SELECT
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default3 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["vy"].ToString());
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from COUNTRY ";
adp.SelectCommand = cmd;
adp.Fill(dt);
DropDownList1.DataTextField = "cname";
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "-select-");
con.Close();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select sname from state where cid=(select cid from country where
cname='"+DropDownList1.Text+"')";
adp.SelectCommand = cmd;
adp.Fill(dt);
DropDownList2.DataTextField = "sname";
DropDownList2.DataSource = dt;
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, "-select-");
DropDownList3.ClearSelection();
con.Close();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select dname from district where sid=(select sid from state where sname='" +
DropDownList2.Text + "')";
adp.SelectCommand = cmd;
adp.Fill(dt);
DropDownList3.DataTextField = "dname";
DropDownList3.DataSource = dt;
DropDownList3.DataBind();
DropDownList3.Items.Insert(0, "-select-");
con.Close();
}
}

SUBJECT: DETAILED VIEW FROM DROP DOWN LIST


using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["vy"].ToString());
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from login ";
adp.SelectCommand = cmd;
adp.Fill(dt);
DropDownList1.DataTextField = "id";
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "-select-");
con.Close();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from login where id=" + DropDownList1.Text;
adp.SelectCommand = cmd;
adp.Fill(dt);
DetailsView1.DataSource = dt;
DetailsView1.DataBind();
con.Close();
}
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{

}
}

SUBJECT: SELECT INSERT UPDATE GRID VIEW

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["v"].ToString());
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
public void fill()
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from emp";
adp.SelectCommand = cmd;
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
public void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
fill();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
fill();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
fill();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gr = GridView1.Rows[Convert.ToInt32(e.RowIndex)];
TextBox t1, t2, t3;
t1 = (TextBox)gr.Cells[0].Controls[0];
t2 = (TextBox)gr.Cells[1].Controls[0];
t3 = (TextBox)gr.Cells[2].Controls[0];
con.Open();
cmd.Connection = con;
cmd.CommandText = "update emp set name='"+t2.Text+"',place='"+t2.Text+"' where id="+t1.Text;
adp.SelectCommand = cmd;
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
GridView1.EditIndex = -1;
fill();

}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = GridView1.SelectedRow.Cells[0].Text;
TextBox2.Text = GridView1.SelectedRow.Cells[1].Text;
TextBox3.Text = GridView1.SelectedRow.Cells[2].Text;
}
}

SUBJECT: SELECT INSERT UPDATE GRID VIEW

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["v"].ToString());
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
public void fill()
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from emp";
adp.SelectCommand = cmd;
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
public void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
fill();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
fill();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
fill();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gr = GridView1.Rows[Convert.ToInt32(e.RowIndex)];
TextBox t1, t2, t3;
t1 = (TextBox)gr.Cells[0].Controls[0];
t2 = (TextBox)gr.Cells[1].Controls[0];
t3 = (TextBox)gr.Cells[2].Controls[0];
con.Open();
cmd.Connection = con;
cmd.CommandText = "update emp set name='"+t2.Text+"',place='"+t2.Text+"' where id="+t1.Text;
adp.SelectCommand = cmd;
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
GridView1.EditIndex = -1;
fill();

}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = GridView1.SelectedRow.Cells[0].Text;
TextBox2.Text = GridView1.SelectedRow.Cells[1].Text;
TextBox3.Text = GridView1.SelectedRow.Cells[2].Text;
}

SUBJECT: SELECT INSERT UPDATE GRID VIEW

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["v"].ToString());
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
public void fill()
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from emp";
adp.SelectCommand = cmd;
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
public void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
fill();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
fill();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
fill();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gr = GridView1.Rows[Convert.ToInt32(e.RowIndex)];
TextBox t1, t2, t3;
t1 = (TextBox)gr.Cells[0].Controls[0];
t2 = (TextBox)gr.Cells[1].Controls[0];
t3 = (TextBox)gr.Cells[2].Controls[0];
con.Open();
cmd.Connection = con;
cmd.CommandText = "update emp set name='"+t2.Text+"',place='"+t2.Text+"' where id="+t1.Text;
adp.SelectCommand = cmd;
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
GridView1.EditIndex = -1;
fill();

}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = GridView1.SelectedRow.Cells[0].Text;
TextBox2.Text = GridView1.SelectedRow.Cells[1].Text;
TextBox3.Text = GridView1.SelectedRow.Cells[2].Text;
}
}

You might also like