如何把文本框里的数据读出来转化成decimal类型存到数据库?
我想把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(); --------------------编程问答-------------------- 直接作为string处理
--------------------编程问答-------------------- 顶··求大侠救命·~~ --------------------编程问答-------------------- Session["UserName"] = "yiyi";
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();
有错误:输入格式不正确 --------------------编程问答-------------------- 确定 TextBox1.Text 不为字符? sql没错 您传过来的值确认下! --------------------编程问答-------------------- string sqlstr1 = " update UserInfo set Account= '"+account+"' where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal
是where buyername=
一个=号不是两个 --------------------编程问答-------------------- 确保你的string值是数值型的。
decimal.Parse(str) --------------------编程问答-------------------- string sqlstr1 = " update UserInfo set Account= '"+decimal.Parse(account)+"' where BuyerName=='" + Session["UserName"] + "'";//确保你的string值是数值型的 --------------------编程问答--------------------
--------------------编程问答--------------------
string sqlstr1 = " update UserInfo set Account= "+account+" where BuyerName=='" + Session["UserName"] + "'";//Account为需要跟新的字段类型是Decimal
不是2个= ,sql没有==;
有错误:输入格式不正确
说明是你传过来的值有问题 !
--------------------编程问答-------------------- demical.parse --------------------编程问答-------------------- 解决了没有啊、 --------------------编程问答-------------------- update UserInfo set Account= '"+account+"' where BuyerName='" + Session["UserName"].ToString()+'" --------------------编程问答-------------------- Session["UserName"] = "yiyi";
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(); --------------------编程问答-------------------- decimal account = Convert.ToDecimal(TextBox1.Text.Trim().ToString());
try catch下。
ps:TextBox1.Text.Trim().已经是字符串了。
补充:.NET技术 , ASP.NET