1.subject: Insert Countrey Base State
1.subject: Insert Countrey Base State
1.subject: Insert Countrey Base State
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
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();
}
}
}
}
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;
}
}
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;
}
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;
}
}