我想把textbox里的数据读出来存到数据库中,数据库中的余额字段是decimal类型,
Session["UserName"] = "yiyi";
decimal account = Convert.ToDecimal(TextBox1.Text.Trim().ToString());
Label16.Text = Session["UserName"].ToString();//要更新的用户名
SqlConnection conn = new SqlConnection("Data Source=;Integrated Security=True");
conn.Open();
string sqlstr1 = "update UserInfo set Account= account where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal,如何写update语句???
SqlCommand cmd1 = new SqlCommand(sqlstr1, conn);
cmd1.ExecuteNonQuery();
Session["UserName"] = "yiyi";
decimal account = Convert.ToDecimal(TextBox1.Text.Trim().ToString());
Label16.Text = Session["UserName"].ToString();//要更新的用户名
SqlConnection conn = new SqlConnection("Data Source=;Integrated Security=True");
conn.Open();
string sqlstr1 = "update UserInfo set Account= account where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal,如何写update语句???
SqlCommand cmd1 = new SqlCommand(sqlstr1, conn);
cmd1.ExecuteNonQuery();
解决方案 »
- asp.net中iframe弹出div时怎么控制div固定的位置
- 帮帮忙,装了Xenocode之后编译项目的时候总进行Postbuild
- 二进制图片插入数据库的问题
- asp网站发布,别人只能访问到一个登陆界面
- 索引超出范围。必须为非负值并小于集合大小。 参数名: index
- 如何可以在ASPX文件中动态的定义自定义控件
- web part 的使用??
- 请教:如何在ASP.net中把二进制文件存入SQL server 2000,并提取出来?谢谢!
- asp.net如何生成html页?
- 在线等待!安装部署问题!
- 请问各位大侠哥哥个问题,我做了个网站 高度和宽度都是固定了的!!文章的内容太长,把页面拉高拉的太难看。如果文章内容太短 没达到设置的高度,就要把文章多条段落要添
- .net中access数据库如何备份到本地
update UserInfo set Account= ‘“+account+”’ where BuyerName=='" + Session["UserName"] + "'
decimal account = Convert.ToDecimal(TextBox1.Text.Trim().ToString());
Label16.Text = Session["UserName"].ToString();//要更新的用户名
SqlConnection conn = new SqlConnection("Data Source=WWW-89CBDBACAB5\\SQLEXPRESS;Initial Catalog=G:\\ESHOP\\APP_DATA\\PaiMai.MDF;Integrated Security=True");
conn.Open();
string sqlstr1 = " update UserInfo set Account= '"+account+"' where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal
SqlCommand cmd1 = new SqlCommand(sqlstr1, conn);
cmd1.ExecuteNonQuery();
有错误:输入格式不正确
是where buyername=
一个=号不是两个
decimal.Parse(str)
string sqlstr1 = " update UserInfo set Account= "+account+" where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal
有错误:输入格式不正确
说明是你传过来的值有问题 !
decimal account = 0.0;
try
{
account = Convert.ToDecimal(TextBox1.Text.Trim().ToString());
}
catch(Exception )
{
ClientScript.RegisterClientScriptBlock(GetType(),"","<script>alert('输入的必须是数字!')</script>");
return;
}
Label16.Text = Session["UserName"].ToString();//要更新的用户名
SqlConnection conn = new SqlConnection("Data Source=;Integrated Security=True");
conn.Open();
string sqlstr1 = "update UserInfo set Account="+account+" where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal,如何写update语句???
SqlCommand cmd1 = new SqlCommand(sqlstr1, conn);
cmd1.ExecuteNonQuery();
try catch下。
ps:TextBox1.Text.Trim().已经是字符串了。