添加/删除/修改数据库内容
在数据库存中插内容
private void Button1_Click(object sender, System.EventArgs e)
{
string b1;
string b2;
string b3;
string b4;
string b5;
b1=this.TextBox1.Text;
b2=this.TextBox2.Text;
b3=this.TextBox3.Text;
b4=this.TextBox4.Text;
b5=this.TextBox5.Text;
System.Data .SqlClient.SqlConnection bb=new System.Data.SqlClient.SqlConnection ("server=(local);database=Hotel;uid=sa;pwd=123");
string dd="INSERT INTO info(publicizer,[goods name],bewrite,price,issuance)VALUES('"+b1+"','"+b2+"','"+b3+"','"+b4+"','"+b5+"')";
System.Data.SqlClient.SqlCommand ef=new System.Data.SqlClient.SqlCommand(dd,bb);
ef.Connection.Open();
ef.ExecuteNonQuery();
Response.Redirect("test4.aspx");
}
在页面建立列表,读出数据库中的内容
private void Page_Load(object sender, System.EventArgs e)
{
System.Data .SqlClient .SqlConnection cc=new System.Data.SqlClient.SqlConnection ("server=(local);database=Hotel;uid=sa;pwd=123");
string tt="select * from info";
System.Data .SqlClient.SqlDataAdapter abc=new System.Data.SqlClient.SqlDataAdapter(tt,cc);
DataSet a12=new DataSet();
abc.Fill (a12);
this.DataGrid1.DataSource=a12;
this.DataGrid1.DataBind();
}
删除数据库的内容
private void Page_Load(object sender, System.EventArgs e)
{
string c = Request.QueryString["abc"];//获取abc的值
System.Data .SqlClient .SqlConnection cc=new System.Data.SqlClient.SqlConnection("server=(local);database=hotel;uid=sa;pwd=123");
string qd="delete from enrol where id=" + c;
System.Data .SqlClient.SqlCommand ef=new System.Data.SqlClient.SqlCommand(qd,cc);
ef.Connection.Open ();
ef.ExecuteNonQuery();
Response.Redirect("test8.aspx"); //跳传页面
更新修改数据库内容
System.Data .SqlClient .SqlConnection cc=new System.Data.SqlClient.SqlConnection("server=(local);database=hotel;uid=sa;pwd=510823");
string qd="update enrol set age=88 where work='工程师'";
System.Data .SqlClient.SqlCommand ef=new System.Data.SqlClient.SqlCommand(qd,cc);
ef.Connection.Open ();
ef.ExecuteNonQuery();
Response .Redirect ("test8.aspx");
posted on 2006-03-22 16:16 Dina's blog 阅读(739) 评论(0) 编辑 收藏 举报