
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace 二班
{
public partial class 增删改查 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string XH = TextBox1.Text;
string XM = TextBox2.Text;
string XB = RadioButtonList1.SelectedItem.Text;
string ZY = DropDownList1.SelectedItem.Text;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=DESKTOP-NIPVNUT;database=11111;Trusted_Connection=SSPI";
conn.Open();
string sql = "INSERT INTO TB_STU ( XH , XM , XB , ZY ) " + "VALUES ( '" + XH + "', '" + XM + "' , '" + XB + "' , '" + ZY + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
Label1.Text = "数据添加成功!";
conn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
string XH = TextBox1.Text;
string XM = TextBox2.Text;
string XB = RadioButtonList1.SelectedItem.Text;
string ZY = DropDownList1.SelectedItem.Text;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=DESKTOP-NIPVNUT;database=11111;Trusted_Connection=SSPI";
conn.Open();
string sql2 = "update TB_STU set XM='" + XM + "'where XH = '" + XH + "'";
string sql3 = "update TB_STU set XB='" + XB + "' where XH = '" + XH + "'";
string sql4 = "update TB_STU set ZY='" + ZY + "' where XH = '" + XH + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
cmd2.ExecuteNonQuery();
SqlCommand cmd3 = new SqlCommand(sql3, conn);
cmd3.ExecuteNonQuery();
SqlCommand cmd4 = new SqlCommand(sql4, conn);
cmd4.ExecuteNonQuery();
Label1.Text = "数据修改成功!";
conn.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
string id = Request.QueryString["id"].ToString();
Label1.Text = "学号为" + id + "学生信息已删除";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=DESKTOP-NIPVNUT;database=11111;Trusted_Connection=SSPI";
conn.Open();
string sql = "Delete FROM TB_STU Where XH = '" + id + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
protected void Button4_Click(object sender, EventArgs e)
{
string XH = TextBox1.Text;
string XM = TextBox2.Text;
string XB = RadioButtonList1.SelectedItem.Text;
string ZY = DropDownList1.SelectedItem.Text;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=DESKTOP-NIPVNUT;database=11111;Trusted_Connection=SSPI";
conn.Open();
string sql = "INSERT INTO TB_STU ( XH , XM , XB , ZY) " + "VALUES ( '" + XH + "', '" + XM + "' , '" + XB + "' , '" + ZY + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
Label1.Text = "数据查找成功!";
conn.Close();
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}