using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Using System. The Data. SqlClient.
using System.Data;
The namespace class 2
{
Public partial class to add and delete: 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. The ConnectionString="server=DESKTOP - NIPVNUT; The database=11111; Trusted_Connection=SSPI ";
Conn. The 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="data add success!" ;
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. The ConnectionString="server=DESKTOP - NIPVNUT; The database=11111; Trusted_Connection=SSPI ";
Conn. The 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="data change success!" ;
Conn. Close ();
}
Protected void Button3_Click (object sender, EventArgs e)
{
String id=Request. The QueryString (" id "). The ToString ();
Label1. Text="student id" + id + "student information deleted";
SqlConnection conn=new SqlConnection ();
Conn. The ConnectionString="server=DESKTOP - NIPVNUT; The database=11111; Trusted_Connection=SSPI ";
Conn. The 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. The ConnectionString="server=DESKTOP - NIPVNUT; The database=11111; Trusted_Connection=SSPI ";
Conn. The 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="data to find success!" ;
Conn. Close ();
}
Protected void RadioButtonList1_SelectedIndexChanged (object sender, EventArgs e)
{
}
}
}
CodePudding user response:
The database name is 11111, didn't you fill in the wrong? If the database is really support and advice library name first letter in English alphabet,This database, the library has TB_STU this table?
CodePudding user response: