数据库插入问题!!!!!!!!!!!!!!!!!!!!
public class sqldata
{
public static OleDbConnection con()
{
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings[ "nfdbConnectionString "].ConnectionString);
return con;
}
public static bool operate(string query)//执行sql语句成功返回真,否则返回假
{
OleDbConnection con = sqldata.con();
con.Open();
OleDbCommand cmd = new OleDbCommand(query,con);
int count = Convert.ToInt32(cmd.ExecuteNonQuery());
if (count > 0)
{
return true;
}
else
{
return false;
}
}
}
---------------------------------------------
DateTime datime = DateTime.Now;
string date = datime.ToString();
sqldata.operate( "INSERT INTO productdetail (name, gaishu, gaikuang, image, date) VALUES ( ' " + name_str + " ', ' " + gs_str + " ', ' " + gk_str + " ', ' " + pathandfile + " ', ' " + date + " ') ");
报错说insert into语句错误!
------解决方案--------------------那如果sql语句中有 '等符号怎么办啊
------
用两个引号表示,如
SELECT ' ' 'HelloWorld ' ' '
输出
'HelloWorld '