当前位置: 首页>>代码示例>>C#>>正文


C# DbManager.SaveChanges方法代码示例

本文整理汇总了C#中DbManager.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DbManager.SaveChanges方法的具体用法?C# DbManager.SaveChanges怎么用?C# DbManager.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DbManager的用法示例。


在下文中一共展示了DbManager.SaveChanges方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: saveExcelFileToDb

 private UploadedFormat31File saveExcelFileToDb(string fullFilePath, UploadedFormat31File uploadedFormat31File)
 {
     uploadedFormat31File.fileName = "F" + uploadedFormat31File.batchNumber + "." + uploadedFormat31File.extension;
     uploadedFormat31File.uploadedFormat31FileId = Guid.NewGuid();
     uploadedFormat31File.Maker = User.Identity.GetUserName();
     uploadedFormat31File.StatusOptions = MyEnums.StatusOptions.Unapproved;
     //Verify that it is excel of the right format
     //Read all fields in first worksheet and save values to db
     //string excelFileConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fullFilePath + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
     string excelFileConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fullFilePath + ";Extended Properties='Excel 8.0;IMEX=1';";
     OleDbConnection excelConn = new OleDbConnection(excelFileConnectionString);
     excelConn.Open();
     OleDbCommand excelOleDbCommand = new OleDbCommand("Select * From [Sheet1$]", excelConn);
     OleDbDataReader dReader = excelOleDbCommand.ExecuteReader();
     int count = 0;
     while (dReader.Read())
     {
         //Branch Code	Account No	FCCY	LCCY	FCY Amount	Exchange Rate	LCY Amount	Value Date	Transaction Code	Reference Number	DR CR	Narrative	RELATEDCUSTOMER	TRSNSOUC	EXPENSE_OUC
         Format31FileData format31FileData = new Format31FileData();
         if (!(DBNull.Value == dReader.GetValue(0))) { format31FileData.branchCode = dReader.GetValue(0).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(1))) { format31FileData.accountNo = dReader.GetValue(1).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(2))) { format31FileData.FCCY = dReader.GetValue(2).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(3))) { format31FileData.LCCY = dReader.GetValue(3).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(4))) { format31FileData.FCYAmount = dReader.GetValue(4).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(5))) { format31FileData.exchangeRate = dReader.GetValue(5).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(6))) { format31FileData.LCYAmount = dReader.GetValue(6).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(7))) { format31FileData.valueDate = dReader.GetValue(7).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(8))) { format31FileData.transactionCode = dReader.GetValue(8).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(9))) { format31FileData.referenceNumber = dReader.GetValue(9).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(10))) { format31FileData.DR_CR = dReader.GetValue(10).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(11))) { format31FileData.narrative = dReader.GetValue(11).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(12))) { format31FileData.relatedCustomer = dReader.GetValue(12).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(13))) { format31FileData.transOUC = dReader.GetValue(13).ToString().Trim(); }
         if (!(DBNull.Value == dReader.GetValue(14))) { format31FileData.expenseOUC = dReader.GetValue(14).ToString().Trim(); }
         format31FileData.index = count;
         count++;
         format31FileData.Format31FileDataId = Guid.NewGuid();
         uploadedFormat31File.fileData.Add(format31FileData);
     }
     dReader.Close();
     //_repository.SaveUpdate(uploadedFormat31File);
     DbManager context = new DbManager();
     context.UploadedFormat31File.Add(uploadedFormat31File);
     context.SaveChanges();
     _sharedCls.LogAudit(User.Identity.GetUserName(), "Save", Request.UserHostName, "Saved Format31 File Data to Database", "Save", "Format31");
     return uploadedFormat31File;
 }
开发者ID:ongeri,项目名称:citieuc,代码行数:47,代码来源:UploadedFormat31FileController.cs


注:本文中的DbManager.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。