namespace QYApplication1
{
    public partial class AddClass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }        protected void Button1_Click(object sender, EventArgs e)        {
            string sql = "insert into class_qy(Class_name) values('" + Textbox1.Text.Trim() + "')";
            string con = ConfigurationManager.ConnectionStrings["SiteMapConnectionString"].ToString();
            SqlConnection sqlConn = new SqlConnection(con);
            SqlCommand sqlCmd = new SqlCommand(sql, sqlConn);
            sqlCmd.Connection.Open();
            sqlCmd.ExecuteNonQuery();
            sqlCmd.Connection.Close();        }
    }页面点击按钮后,数据库中还是增加不了数据,但是执行时没有显示错误信息,请各位大大帮帮忙。}

解决方案 »

  1.   

    protected void Button1_Click(object sender, EventArgs e) {
    有執行碼?
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head><body>
        <form id="form1" runat="server">
        <div  align="center">
        企业分类:<asp:textbox ID="Textbox1" runat="server"></asp:textbox><br />
            <asp:Button ID="Button1" runat="server" Text="提交分类" onclick="Button1_Click" />
        </div>
        </form>
    </body>
    </html>
    点击按钮后没反映,按钮没有执行吗??刚学不久,请指教一下
      

  3.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
      <title></title>
    </head><body>
      <form id="form1" runat="server">
      <div align="center">
      企业分类:<asp:textbox ID="Textbox1" runat="server"></asp:textbox><br />
      <asp:Button ID="Button1" runat="server" Text="提交分类" OnClick="Button1_Click" />
      </div>
      </form>
    </body>
    </html> protected void Button1_Click(object sender, EventArgs e)
     {
       try
       {
          string sql = "insert into class_qy(Class_name) values('" + Textbox1.Text.Trim() + "')";
          string con = ConfigurationManager.ConnectionStrings["SiteMapConnectionString"].ToString();
          SqlConnection sqlConn = new SqlConnection(con);
          sqlConn.Open();
          SqlCommand sqlCmd = new SqlCommand(sql, sqlConn);
          sqlCmd.ExecuteNonQuery();
          sqlCmd.Connection.Close();
        }
         catch(Exception ex)
        {
           Response.Write(ex.Message);
        }
    }
      

  4.   

    正解
    <asp:Button ID="Button1" runat="server" Text="提交分类" onclick="Button1_Click" />
    应该是OnClick