数据库编写不易 [英] Truble with database writing
本文介绍了数据库编写不易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string [] split = Arr [i] .Split(''|'');
字符串sqlCmd ="INSERT INTO table1(ID,Region,Name)" +
"VALUES(" + split [0] +'',''+ split [1] +'',''+ split [2] +)";
我得到一个OleDbException:缺少参数.
Arr []包含以下字符串:
0001 | sddfg | dfg dfgh
请帮忙.
string[] split = Arr[i].Split(''|'');
string sqlCmd = "INSERT INTO table1 (ID, Region, Name) " +
"VALUES (" + split[0] + '','' + split[1] + '','' + split[2] + ")";
and I get an OleDbException: missing parameter.
Arr[] contains strings like this:
0001|sddfg|dfg dfgh
Please, help.
推荐答案
为什么要手动插入ID?自动递增是更好的做法.
您还会在要插入的(我假设为varchar)值周围缺少''标记.
我会尝试这样的事情:
Why are you inserting the ID manually? Its better practise to have it auto-increment.
You are also missing '' marks around the (I assume varchar) values you are inserting.
I would try something like this:
split = Arr [i] .Split(''|'');
字符串sqlCmd ="INSERT INTO table1(Region,Name)" +
"VALUES(""+ split [1] +"''," + split [2] +'')";
split = Arr[i].Split(''|'');
string sqlCmd = "INSERT INTO table1 (Region, Name) " +
"VALUES (''" + split[1] + "'',''" + split[2] + "'')";
这篇关于数据库编写不易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文