问题描述
privatestringInsertEntity(DataRowdsRow,ArrayListaList,stringtbName){intj=0;stringsReturn="-1";stringstrInsert="",strValues="",strField,sValue="";//boolbContinue=true;FieldDefField;stringstrIdentity="";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="insertinto"+tbName+"("+strField;elsestrInsert+=","+strField;if(strValues=="")strValues="values(";elsestrValues+=",";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";elsesValue="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(Exceptione){sReturn=e.ToString();}returnsReturn;}
解决方案
解决方案二:
把一行记录dsRow插入表tbName中aList是自增列!