将textBox中读到的值,加到数据库中
数据库表中有个字段为,count,我希望,读取textBox中的值,然后update这张表中的count,使得新count=原来的count和textBox中值之和先谢过...
数据库表中有个字段为,count,我希望,读取textBox中的值,然后update这张表中的count,使得 新count = 原来的count 和 textBox中值之和
先谢过 展开
先谢过 展开
1个回答
展开全部
using System;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=.;database=dnt;user id=sa;pwd=123;"))
{
//tbxCount为文本框的id
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("update dnt_users set newpmcount = newpmcount + "+int.Parse(this.tbxCount.Text)+" where uid=1", conn))
{
try
{
conn.Open();
cmd.ExecuteNonQuery();
Response.Write("操作成功");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
}
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=.;database=dnt;user id=sa;pwd=123;"))
{
//tbxCount为文本框的id
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("update dnt_users set newpmcount = newpmcount + "+int.Parse(this.tbxCount.Text)+" where uid=1", conn))
{
try
{
conn.Open();
cmd.ExecuteNonQuery();
Response.Write("操作成功");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
}
参考资料: http://www.sosuo8.com/
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询