表名 Book_Info
列分别为:Book_ID(varchar), Book_Name(varchar),Writer(varchar),Press(varchar),Price(float)
我想插入一条语句:str="Insert into Book_Info(Book_ID,Book_Name,Writer,Press,Price)"
" VALUES('m_BookID','m_BookName','m_Write','m_Press', m_Price ) ";其中: m_BookID , m_BookName, m_Write ,m_Press 均为CSting类型。 m_Price 为long类型,一运行报错:在此上下文中不允许使用m_Price 。此处允许使用常量,表达式或变量。不允许使用列名。 我这里的m_Price 就是一个变量。
把m_Price 加上单引号变成str="Insert into Book_Info(Book_ID,Book_Name,Writer,Press,Price)"
" VALUES('m_BookID','m_BookName','m_Write','m_Press', ‘m_Price’ ) ";又提示:将数据类型vachar转换成float出错。
无语了,应该怎么改?????求指点。
列分别为:Book_ID(varchar), Book_Name(varchar),Writer(varchar),Press(varchar),Price(float)
我想插入一条语句:str="Insert into Book_Info(Book_ID,Book_Name,Writer,Press,Price)"
" VALUES('m_BookID','m_BookName','m_Write','m_Press', m_Price ) ";其中: m_BookID , m_BookName, m_Write ,m_Press 均为CSting类型。 m_Price 为long类型,一运行报错:在此上下文中不允许使用m_Price 。此处允许使用常量,表达式或变量。不允许使用列名。 我这里的m_Price 就是一个变量。
把m_Price 加上单引号变成str="Insert into Book_Info(Book_ID,Book_Name,Writer,Press,Price)"
" VALUES('m_BookID','m_BookName','m_Write','m_Press', ‘m_Price’ ) ";又提示:将数据类型vachar转换成float出错。
无语了,应该怎么改?????求指点。
怎么才能看到啊 不知道怎么搞啊。
第一个错误提示就是:在此上下文中不允许使用m_Price 。此处允许使用常量,表达式或变量。
第二个错误提示是:将数据类型vachar转换成float时出错。
" VALUES('m_BookID','m_BookName','m_Write','m_Press', ‘m_Price’ ) ";
Book_Info(Book_ID,Book_Name,Writer,Press,cast(Price as varchar(10))
select
'm_BookID','m_BookName','m_Write','m_Press', ‘m_Price’
" VALUES('m_BookID','m_BookName','m_Write','m_Press', m_Price) ";首先不说语句,就两个字符串都没加吧,如果你后面的是变量
m_Price
你用参数形式看看,你的点点可能不对
" VALUES('m_BookID','m_BookName','m_Write','m_Press', "+m_Price+" ) ";
str="Insert into Book_Info(Book_ID,Book_Name,Writer,Press,Price)"
" VALUES('m_BookID','m_BookName','m_Write','m_Press', ‘m_Price’ ) ";
m_db.ExecuteSQL(str);
其中m_db为Cdatabase类
str="Insert into Book_Info(Book_ID,Book_Name,Writer,Press,Price)
VALUES('m_BookID','m_BookName','m_Write','m_Press', m_Price ) ";
m_db.ExecuteSQL(str);这样应该可以吧,我也没试过!可能就是符号的问题而已!
CString str;
str="Insert into Book_Info(Book_ID,Book_Name,Writer,Press,Price)"+
"VALUES("+ "'"+m_BookID+"','"+ m_BookName+"','+ m_Write+"','"+m_Press+", "+ m_Price +") ";m_db.ExecuteSQL(str);
试试,
在SQL中char型的要加''的。在C#中利用""模拟
" VALUES('m_BookID','m_BookName','m_Write','m_Press', m_Price ) ";
+@"VALUES('{0}','{1}','{2}','{3}',{4}) ";str=string.Format(str,m_BookID,m_BookName,m_Write,m_Press,m_Price);这个str 应该才是要执行的SQL 吧