OleDbParameter[] parameters = new OleDbParameter[]
{
new OleDbParameter("@Cname", DbType.String)
};
parameters[0].Value = model.Name;
StringBuilder sql = new StringBuilder();
string sqls = "update ArticleCategories set Cname='1234' where Cid=@Cid";//这行执行起来没问题
string sqls = "update ArticleCategories set Cname=@Cname where Cid=@Cid";//这行就不行,晕了。啥原因啊?
return OleDbDBHelper.ExecuteNonQuery(sqls.ToString(), parameters) > 0;
//这是C#在操作Access数据库时出现的, Cid=@Cid就没事,set Cname=@Cname 就不行,请问是啥原因啊?
parameter类型你设置下input(输入参数类型)试试看。
文本格式,DbType.String有错吗?
@安美奇: (parameterName, parameterValue, dbType, parameterSize, ParameterDirection.Input);
@卿君: 汗。。。。。。不懂。。。
@安美奇: {
new OleDbParameter("@Cname", DbType.Nvarchar,50,ParameterDirection.Input)
};
注:ParameterDirection参数类型,input表示需要输入型参数,output输出型参数。Cname作为参数传入故input类型参数。明白了?最好你再去园子搜索几篇文章再理解消化一下
@卿君: OleDbParameter[] parameters = new OleDbParameter[]
{
new OleDbParameter("@Cname", OleDbType.VarWChar),
new OleDbParameter("@Pid", OleDbType.BigInt),
new OleDbParameter("@IndexTitle",OleDbType.VarWChar),
new OleDbParameter("@isLeaf", OleDbType.Boolean),
new OleDbParameter("@Cid", OleDbType.BigInt)
};
parameters[0].Value = model.Name;
parameters[1].Value = model.ParentId;
parameters[2].Value = model.IndexName;
parameters[3].Value = model.IsLeaf;
parameters[4].Value = model.Id;
StringBuilder sql = new StringBuilder();
//string sqls = "update ArticleCategories set Cname='1234567890' where Cid=@Cid";
string sqls = "update ArticleCategories set Cname=@Cname,Pid=@Pid,IndexTitle=@IndexTitle,isLeaf=@isLeaf where Cid=@Cid";
return OleDbDBHelper.ExecuteNonQuery(sqlqs.ToString(), parameters) > 0;
参数化的问题咯
什么意思啊?
string sqls = "update ArticleCategories set Cname=@Cname where Cid=@Cid";
这个sql语句中你有两个参数Cname和Cid,但是OleDbParameter数组中却只有一个参数Cname
ACCESS中参数冒似顺序错了就会出错.