这500条命令都是执行的switch里面的插入命令:AddToDb,其中AddToDb组织sql语句。代码如下:
public bool AddToDb(PropertyCollection props)
{
if (props == null)
return false;
StringBuilder strSql = new StringBuilder("insert into ");
strSql.Append(props.TblName);
strSql.Append(" ( ");
StringBuilder strVals = new StringBuilder(" values (");
int count = props.Count;
for (int i = 0; i
{
PropertyVal val = (PropertyVal)props.GetPropertyList()[i];
strSql.Append(val.Name);
strVals.Append('?');
if (i != (count - 1))
{
strSql.Append(',');
strVals.Append(',');
}
}
strSql.Append(')');
strVals.Append(')');
ParameterCollection Paras = new ParameterCollection(this.GetDbFactory(), this.DBCommand, this.m_bEncoding);
Paras.Clear();
logInfo = "";
foreach (PropertyVal val in props.GetPropertyList())
{
if ((this.DbType == DbType.Access) && (val.Val.GetType() == typeof(DateTime)))
{
DateTime time = (DateTime)val.Val;
Paras.Add("@" + val.Name, DateTime2UnixTime(time));
}
else
{
Paras.Add("@" + val.Name, val.Val);
}
logInfo += string.Format("{0} = {1}", val.Name, val.Val.ToString());
}
strSql.Append(strVals.ToString());
string strSqlCommand = strSql.ToString();
logInfo += string.Format("SQL = {0}", strSqlCommand);
if (this.PreDbOperate != null)
{
DbOperateRecord dop = new DbOperateRecord();
dop.DBO = this;
dop.SetParameter(this.DBCommand.Parameters);
dop.SqlCommand = strSqlCommand;
dop.Operator = DbOperator.AddRecord;
dop.RecordObj = props.RecordObj;
dop.DbTableName = props.TblName;
this.PreDbOperate(dop);
}
bool res = false;
try
{
res = this.Db_ExecuteNonQuery(strSqlCommand);
}
catch (System.Exception ex)
{
logInfo += " 异常信息:" + ex.ToString();
}
return res;
}