C#编写的小程序中,将变量插入数据库中出错了,
数据库连接没有问题,编译时编译器提示“System.Data.OleDb.OleDbException”类型的未经处理的异常出现在System.Data.dll中。其他信...
数据库连接没有问题,编译时编译器提示“System.Data.OleDb.OleDbException”类型的未经处理的异常出现在System.Data.dll中。
其他信息:INSERT INTO语句语法错误。
代码如下,请各位高手帮下忙
string ConStr2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Striver\\Desktop\\goodsdata.mdb";
OleDbConnection Conn2 = new OleDbConnection(ConStr2);
string strSQL = "insert into [goodsinfo] (serial,names,price,made,color,material,imageurl1,imageurl2,imageurl3,imageurl4,imageurl5) values";
strSQL += "(" +goodsquesse + "," +goodstitle+ "," + goodsprice + "," + goodsmade + "," + goodcolor + ",";
strSQL += goodmaterial + "," + imageurl1 + "," + imageurl2 + "," + imageurl3 + "," + imageurl4 + "," + imageurl5 + ")";
Conn2.Open();
OleDbCommand Cmd1 = new OleDbCommand(strSQL, Conn2);
Cmd1.ExecuteNonQuery();
Conn2.Close(); 展开
其他信息:INSERT INTO语句语法错误。
代码如下,请各位高手帮下忙
string ConStr2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Striver\\Desktop\\goodsdata.mdb";
OleDbConnection Conn2 = new OleDbConnection(ConStr2);
string strSQL = "insert into [goodsinfo] (serial,names,price,made,color,material,imageurl1,imageurl2,imageurl3,imageurl4,imageurl5) values";
strSQL += "(" +goodsquesse + "," +goodstitle+ "," + goodsprice + "," + goodsmade + "," + goodcolor + ",";
strSQL += goodmaterial + "," + imageurl1 + "," + imageurl2 + "," + imageurl3 + "," + imageurl4 + "," + imageurl5 + ")";
Conn2.Open();
OleDbCommand Cmd1 = new OleDbCommand(strSQL, Conn2);
Cmd1.ExecuteNonQuery();
Conn2.Close(); 展开
5个回答
展开全部
字符型字段的值要加引号。
如果提示有问题可以加上try,这样会提示具体的错误是什么
try
{
代码;
}
catch (Exception ex)
{
ex.Message;
}
ex.Message会告诉你具体的问题是什么。
如果提示有问题可以加上try,这样会提示具体的错误是什么
try
{
代码;
}
catch (Exception ex)
{
ex.Message;
}
ex.Message会告诉你具体的问题是什么。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
字符串你没加单引号
strSQL += "(" +goodsquesse + "," +goodstitle+ "," + goodsprice + "," + goodsmade + "," + goodcolor + ",";
strSQL += goodmaterial + "," + imageurl1 + "," + imageurl2 + "," + imageurl3 + "," + imageurl4 + "," + imageurl5 + ")";
改成一下
strSQL += "(‘" +goodsquesse + "’,‘" +goodstitle+ "’,‘" + goodsprice + "‘,’" + goodsmade + "’,‘" + goodcolor + "’,‘";
strSQL += goodmaterial + "’,‘" + imageurl1 + "’,‘" + imageurl2 + "’,‘" + imageurl3 + "’,‘" + imageurl4 + "’,‘" + imageurl5 + "’)";
strSQL += "(" +goodsquesse + "," +goodstitle+ "," + goodsprice + "," + goodsmade + "," + goodcolor + ",";
strSQL += goodmaterial + "," + imageurl1 + "," + imageurl2 + "," + imageurl3 + "," + imageurl4 + "," + imageurl5 + ")";
改成一下
strSQL += "(‘" +goodsquesse + "’,‘" +goodstitle+ "’,‘" + goodsprice + "‘,’" + goodsmade + "’,‘" + goodcolor + "’,‘";
strSQL += goodmaterial + "’,‘" + imageurl1 + "’,‘" + imageurl2 + "’,‘" + imageurl3 + "’,‘" + imageurl4 + "’,‘" + imageurl5 + "’)";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
字符型字段没有单引号
如:
strSQL += "(" +goodsquesse + "," +goodstitle+ "," + goodsprice + "," + goodsmade + "," + goodcolor + ",";
改成
strSQL += "('" +goodsquesse + "','" +goodstitle+ "'," + goodsprice + ","' + goodsmade + "','" + goodcolor + "',";
...
如:
strSQL += "(" +goodsquesse + "," +goodstitle+ "," + goodsprice + "," + goodsmade + "," + goodcolor + ",";
改成
strSQL += "('" +goodsquesse + "','" +goodstitle+ "'," + goodsprice + ","' + goodsmade + "','" + goodcolor + "',";
...
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上两位说的对,没有单引号。
.cs代码里变量值一定要加单引号踩可以用
.cs代码里变量值一定要加单引号踩可以用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
只学了一点C语言,这个有点深,不懂!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询