public void Import() { DataSet data = this.ExcelToDS("案件类别.xls"); long index = 100000; foreach (System.Data.DataRow row in data.Tables[0].Rows) { string typeName = row.ItemArray[2] as string; string typeDescription = row.ItemArray[3] as string; string sql = string.Format("select count(*) from datatypemappers where TypeID = 'Base.DataAccess.CaseType' and TypeName = '{0}'", typeName); int total = Convert.ToInt32(MySqlHelper.ExecuteScalar(connStr, sql).ToString()); if (total < 1) { DataTypeMapper temp = new DataTypeMapper(); temp.TypeDescription = typeDescription; temp.TypeID = "Base.DataAccess.CaseType"; temp.TypeName = typeName; temp.TypeValue = index++; temp.UpdatedTime = temp.CreatedTime = DateTime.Now; temp.UpdatedUser = temp.CreatedUser = "******"; temp.IsSystemValue = false; this.CreateDataTypeMapper(temp); } } }
private void CreateDataTypeMapper(DataTypeMapper dataType) { string sql = "INSERT INTO DataTypeMappers (TypeValue, TypeName, TypeDescription, TypeID, IsSystemValue, CreatedUser, CreatedTime, UpdatedUser, UpdatedTime) VALUES (@TypeValue, @TypeName, @TypeDescription, @TypeID, @IsSystemValue, @CreatedUser, @CreatedTime, @UpdatedUser, @UpdatedTime );"; using (IDbConnection conn = OpenConnection()) { int id = conn.ExecuteScalar <int>(sql, dataType); } }