注册 登录
编程论坛 SQL Server论坛

[求助]INSERT 问题

fandgg 发布于 2007-09-11 18:40, 519 次点击

string strtitle = this.txttitle.Text.Trim(); //为textbox 表里为varchar
string strprice = this.txtprice.Text.Trim(); //为textbox 表里为money
string connstr = ("database=pubs;uid=sa;pwd=;server=.;");
SqlConnection conn = new SqlConnection(connstr);
string comm = "insert into titles(title,price,title_id,title) values ('"+strtitle+"','"+strprice+"',3212,3000)";
SqlCommand command = new SqlCommand(comm,conn);
conn.Open();
command.ExecuteNonQuery();
conn.Close();

this.BindToGrid();

“/rr1”应用程序中的服务器错误。
--------------------------------------------------------------------------------

不允许从数据类型 varchar 到数据类型 money 的隐性转换(表 'pubs.dbo.titles',列 'price')。请使用 CONVERT 函数来运行此查询。

3 回复
#2
fandgg2007-09-11 18:56

在线等啊。。。。

#3
西风独自凉2007-09-11 19:13
到哪 一句出現這個錯誤。。。
#4
bygg2007-09-11 19:39
string comm = "insert into titles(title,price,title_id,title) values ('"+strtitle+"','"+strprice+"',3212,3000)";
__________________________
+"','"+strprice+"',3212,3000)"; 改成 +"',"+strprice+",3212,3000)";
1