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();
}
}
-2
A
回答
0
你错过了实际的命令执行的呼叫:
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@str", str);
cmd.Parameters.AddWithValue("@base", base1);
cmd.ExecuteNonQuery(); // <--- this line here
con.Close();
我也强烈建议你包在一个using
的连接所以你不会不小心把它打开:
using(SqlConnection con = new SqlConnection(...))
{
con.Open();
/*
rest of code here
*/
con.Close();
}
+0
这就是我错过了cmd.Exec ...行!谢谢!!! – user2708783
+0
没问题,很高兴我能帮到你。 – valverij
+0
给你另外一个问题。我在这个页面上有多个复选框。我如何设置一个更新语句,根据问题编号更改“问题”列? – user2708783
相关问题
- 1. 更新数据库的按钮按不是复选框检查
- 2. Rails-使用复选框来更新数据库而无需提交按钮
- 3. 更新领域数据库与复选框与轨道上的提交按钮
- 4. 使用提交按钮复选框到MySQL数据库
- 5. 复选框和sql数据库更新
- 6. 使用复选框更新对象值,并提交按钮
- 7. 复选框提交到MySQL数据库
- 8. 使用提交按钮更新数据库数据
- 9. 单选按钮不提交数据
- 10. 从提交选项更新数据库
- 11. HTML - PHP - 的onclick()提交按钮来更新SQL Server的价值
- 12. 使用PHP更新SQL数据库中的复选框数据
- 13. 提交复选框状态没有提交按钮
- 14. 不能更改提交到SQL Server Compact Edition数据库
- 15. mvc4复选框更新数据库
- 16. ENUM复选框更新数据库
- 17. 更新数据库中复选框
- 18. JQgrid复选框onclick更新数据库
- 19. 从复选框更新Sqlite数据库
- 20. 更新数据库与复选框
- 21. 复选框和数据库更新
- 22. PHP和SQL(试图使用提交按钮更新我的数据库)
- 23. 使用颜色框上的提交按钮更新mysql数据库
- 24. 如何修改数据库中复选框的值以及如何在提交按钮后显示复选框
- 25. SQL选择重复发生的交易在SQL Server数据库
- 26. 根据至少1/10复选框禁用提交按钮
- 27. form.submit()发布复选框数据与标准提交按钮不同吗?
- 28. 选中多个复选框并提交按钮
- 29. 点击复选框按钮,将显示文本框并提交按钮,点击提交按钮应该禁用复选框按钮
- 30. 按钮提交到数据库错误
你忘了问一个问题。 – tnw