private string InsertEntity(DataRow dsRow, ArrayList aList, string tbName)
{
int j = 0;
string sReturn = "-1";
string strInsert = "", strValues = "", strField, sValue = "";
//bool bContinue = true;
FieldDef Field;
string strIdentity = "";
try
{
for (j = 0; j < aList.Count; j++)
{
Field = (FieldDef)aList[j];
strField = Field.fieldName;
if (dsRow.Table.Columns.Contains(strField))
{
sValue = dsRow[strField].ToString();
sValue = sValue.Replace("'", "''");
if (Field.bisKey == "1" && Field.sequenceName == "1")
{
strIdentity = " SELECT @@IDENTITY " + Field.fieldName;
}
else
{
if (sValue != "")
{
if (Field.bisKey == "1")
sReturn = sValue;
if (strInsert == "")
strInsert = "insert into " + tbName + "(" + strField;
else
strInsert += "," + strField;
if (strValues == "")
strValues = "values(";
else
strValues += ",";
switch (Field.DataType.ToLower())
{
case "int":
case "float":
strValues += sValue;
break;
case "date":
strValues += "'" + sValue + "'";
break;
case "varchar":
strValues += "'" + sValue + "'";
break;
case "bit":
if (sValue.ToLower() == "true")
sValue = "1";
else
sValue = "0";
strValues += sValue;
break;
default:
strValues += "'" + sValue + "'";
break;
}
}
}
}
}
if (strInsert != "")
{
strInsert += ") ";
strValues += ")";
if (sReturn == "-1")
sReturn = "1";
if (strIdentity == "")
{
dbConn.ExecuteSqlWithTrans(strInsert + strValues);
}
else
{
sReturn = dbConn.ReturnStringWithTrans(strInsert + strValues + strIdentity);
}
}
}
catch (Exception e)
{
sReturn = e.ToString();
}
return sReturn; }
{
int j = 0;
string sReturn = "-1";
string strInsert = "", strValues = "", strField, sValue = "";
//bool bContinue = true;
FieldDef Field;
string strIdentity = "";
try
{
for (j = 0; j < aList.Count; j++)
{
Field = (FieldDef)aList[j];
strField = Field.fieldName;
if (dsRow.Table.Columns.Contains(strField))
{
sValue = dsRow[strField].ToString();
sValue = sValue.Replace("'", "''");
if (Field.bisKey == "1" && Field.sequenceName == "1")
{
strIdentity = " SELECT @@IDENTITY " + Field.fieldName;
}
else
{
if (sValue != "")
{
if (Field.bisKey == "1")
sReturn = sValue;
if (strInsert == "")
strInsert = "insert into " + tbName + "(" + strField;
else
strInsert += "," + strField;
if (strValues == "")
strValues = "values(";
else
strValues += ",";
switch (Field.DataType.ToLower())
{
case "int":
case "float":
strValues += sValue;
break;
case "date":
strValues += "'" + sValue + "'";
break;
case "varchar":
strValues += "'" + sValue + "'";
break;
case "bit":
if (sValue.ToLower() == "true")
sValue = "1";
else
sValue = "0";
strValues += sValue;
break;
default:
strValues += "'" + sValue + "'";
break;
}
}
}
}
}
if (strInsert != "")
{
strInsert += ") ";
strValues += ")";
if (sReturn == "-1")
sReturn = "1";
if (strIdentity == "")
{
dbConn.ExecuteSqlWithTrans(strInsert + strValues);
}
else
{
sReturn = dbConn.ReturnStringWithTrans(strInsert + strValues + strIdentity);
}
}
}
catch (Exception e)
{
sReturn = e.ToString();
}
return sReturn; }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货