C# 提交按钮和复选框不更新sql server数据库

C# 提交按钮和复选框不更新sql server数据库,c#,asp.net,sql-server,webforms,C#,Asp.net,Sql Server,Webforms,}您缺少实际命令的执行调用: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDownList1.DataSource = (DataTable)Session["dt"]; DropDownList1.DataValueField = "base"; DropDownList1

}您缺少实际命令的执行调用:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.DataSource = (DataTable)Session["dt"];
            DropDownList1.DataValueField = "base";
            DropDownList1.DataTextField = "base";
            DropDownList1.DataBind();
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {


    }

    string str;
    string email;
    string base1;

    protected void Submit_Click(object sender, EventArgs e)
    {
        if (CheckBox9.Checked == true)
        {
            str = str + CheckBox9.Text + 'x';
        }


    SqlConnection con = new SqlConnection(...);
    String sql = "UPDATE INQUIRY2 set Question1 = @str WHERE email = @email AND base = @base;";

    SqlCommand cmd = new SqlCommand(sql, con);
    con.Open();

    DataTable theDataTable = null;

       // Verify that dt is actually in session before trying to get it

        if(Session["dt"] != null)
        {
            theDataTable = Session["dt"] as DataTable;
        }



    //Verify that the data table is not null
    if(theDataTable != null)
    {
        email = theDataTable.Rows[0]["email"].ToString();
        base1 = theDataTable.Rows[0]["base"].ToString();
    }

    cmd.Parameters.AddWithValue("@email", email);
    cmd.Parameters.AddWithValue("@str", str);
    cmd.Parameters.AddWithValue("@base", base1);

    con.Close();  

    }

}

你忘了问一个问题。这正是我错过的cmd.Exec。。。线谢谢没问题,很高兴我能帮上忙。还有一个问题要问你。我在这个页面上有多个复选框。如何设置根据问题编号更改问题列的更新语句?
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@str", str);
cmd.Parameters.AddWithValue("@base", base1);

cmd.ExecuteNonQuery(); // <--- this line here

con.Close(); 
using(SqlConnection con = new SqlConnection(...))
{
    con.Open();

    /*
        rest of code here
    */

    con.Close();
}