语句先判断要删除表的对象是否存在,如果存在则插入一条新数据,如果不存在则先创建一个删除表,再插入相应数据
表对象:TableName
删除表对象:TableName_deled
主键ID:pCol
其它列名:Fields
if (!TableName.Contains("_deled"))
{
string tbname = TableName + "_deled";
try
{
string sql = "set identity_insert " + tbname + " on;";
sql += "insert into " + tbname + " (" + pCol + "," + Fields + ") select " + pCol + "," + Fields + " from " + TableName + " where " + pCol + " in (" + ids + ");";
sql += "set identity_insert " + tbname + " off;";
ExecuteSql(sql);
}
catch { ExecuteSql("select * into " + TableName + "_deled from " + TableName + " where " + pCol + " in (" + ids + ")"); }
}