public partial class _Default : System.Web.UI.Page
{
string constr = "server=192.168.1.113;database=HH;Uid=sa;pwd=000000;";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
public void Bind()
{
string sqlstr = "select * from Test01";
SqlConnection sqlConn = new SqlConnection(constr);
SqlDataAdapter sda = new SqlDataAdapter(sqlstr, sqlConn);
DataSet ds = new DataSet();
sda.Fill(ds);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
sqlConn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
string sqlStr = "insert into Test01(用戶名稱,用戶郵箱) VALUES ('" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "')";
SqlConnection sqlConn = new SqlConnection(constr);
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand(sqlStr, sqlConn);
sqlCmd.ExecuteNonQuery();
sqlConn.Close();
this.Bind();
}
protected void Button2_Click(object sender, EventArgs e)
{
string sqlstr1 = "delete from Test01 where 用戶名稱 = 'TextBox3.Text.Trim()'";
SqlConnection Con = new SqlConnection(constr);
Con.Open();
SqlCommand Cmd = new SqlCommand(sqlstr1, Con);
Cmd.ExecuteNonQuery();
Con.Close();
this.Bind();
為什麼可以添加數據,刪除卻報錯啊?
string sqlstr1 = "delete from Test01 where 用戶名稱 = '"+TextBox3.Text.Trim()+"'";