insert into时 必须声明标量变量的问题 30
报错必须声明标量变量@guid下面是具体函数publicboolinsert(JcShop.Model.Admin.Goods.Jc_Shopping_Sortmodel...
报错必须声明标量变量@guid
下面是具体函数
public bool insert(JcShop.Model.Admin.Goods.Jc_Shopping_Sort model)
{
StringBuilder SqlStr = new StringBuilder();
SqlStr.Append(@"insert into Jc_Shoping_Sort(
guid,
shoppingsort,
sortguid,
sortnum,
sort
)values(
@guid,
@shoppingsort,
@sortguid,
@sortnum,
@sort
)");
OleDbParameter[] parameters ={
new OleDbParameter("@guid",OleDbType.VarChar),
new OleDbParameter("@shoppingsort",OleDbType.VarChar),
new OleDbParameter("@sortguid",OleDbType.VarChar),
new OleDbParameter("@sortnum",OleDbType.Integer),
new OleDbParameter("@sort",OleDbType.Integer)
};
parameters[0].Value = model.Guid;
parameters[1].Value = model.Shoppingsort;
parameters[2].Value = model.Sortguid;
parameters[3].Value = model.Sortnum;
parameters[4].Value = model.Sort;
int i = JcShop.Helps.DataHelps.DbHelperOleDb.ExecuteSql(SqlStr.ToString(), parameters);
if (i > 0)
return true;
else return false;
}
public static int ExecuteSql(string SQLString, params OleDbParameter[] cmdParms)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
using (OleDbCommand cmd = new OleDbCommand())
{
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
int rows = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return rows;
}
catch (System.Data.OleDb.OleDbException E)
{
throw new Exception(E.Message);
}
}
}
}
private static void PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, string cmdText, OleDbParameter[] cmdParms)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = CommandType.Text;//cmdType;
if (cmdParms != null)
{
foreach (OleDbParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
} 展开
下面是具体函数
public bool insert(JcShop.Model.Admin.Goods.Jc_Shopping_Sort model)
{
StringBuilder SqlStr = new StringBuilder();
SqlStr.Append(@"insert into Jc_Shoping_Sort(
guid,
shoppingsort,
sortguid,
sortnum,
sort
)values(
@guid,
@shoppingsort,
@sortguid,
@sortnum,
@sort
)");
OleDbParameter[] parameters ={
new OleDbParameter("@guid",OleDbType.VarChar),
new OleDbParameter("@shoppingsort",OleDbType.VarChar),
new OleDbParameter("@sortguid",OleDbType.VarChar),
new OleDbParameter("@sortnum",OleDbType.Integer),
new OleDbParameter("@sort",OleDbType.Integer)
};
parameters[0].Value = model.Guid;
parameters[1].Value = model.Shoppingsort;
parameters[2].Value = model.Sortguid;
parameters[3].Value = model.Sortnum;
parameters[4].Value = model.Sort;
int i = JcShop.Helps.DataHelps.DbHelperOleDb.ExecuteSql(SqlStr.ToString(), parameters);
if (i > 0)
return true;
else return false;
}
public static int ExecuteSql(string SQLString, params OleDbParameter[] cmdParms)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
using (OleDbCommand cmd = new OleDbCommand())
{
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
int rows = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return rows;
}
catch (System.Data.OleDb.OleDbException E)
{
throw new Exception(E.Message);
}
}
}
}
private static void PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, string cmdText, OleDbParameter[] cmdParms)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = CommandType.Text;//cmdType;
if (cmdParms != null)
{
foreach (OleDbParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询