求助高手-这个数据库操作基类的作用

xujunyyf917 2012-04-19 12:47:45
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;

}
...全文
51 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
laichunlin 2012-04-19
  • 打赏
  • 举报
回复
把一行记录dsRow 插入表tbName中 aList是自增列!

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧