简单SQL语句,哪儿错了??????
OleDbConnection cn = IConnection.Open();
string sql = "insert into tbUser(Name,NickName,Password,Sex) values( ";
sql += " ' "+ user.Name + " ', ' " + user.NickName + " ', ' " + user.Password + " ', " + user.Sex + "); ";
OleDbCommand cmd = new OleDbCommand(sql, cn);
cmd.ExecuteNonQuery();
IConnection.Close();
执行cmd.ExecuteNonQuery();时出现异常:
2007-05-21 12:56:26,953 [14] FATAL MyLogs [(null)] <(null)> - INSERT INTO 语句的语法错误。
看了半天也没发现哪儿写错了
------解决方案--------------------string sql = "insert into tbUser(Name,NickName,Password,Sex) values( ' ";
sql += " ', "+ user.Name + " ', ' " + user.NickName + " ', ' " + user.Password + " ', " + user.Sex + ") ";
------解决方案--------------------insert into tbUser([Name],[NickName],[Password],[Sex])
------解决方案--------------------最后的分号去掉,另外建议你编写的时候给字段加上[]因为有的字段你用了关键字
比如password
------解决方案--------------------有值为空,数据库限制为非空
------解决方案--------------------最简单的方法:把你生成的SQL语句放到查询分析器中直接执行一下看看是不是正确的?