Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. using (SqlConnection SqlConnection = new SqlConnection(connectionString))
  2. {
  3. SqlConnection.Open();
  4.  
  5.  
  6.  
  7. using (SqlCommand cmdCreateINHResponseTableSP = new SqlCommand("CreateSP", SqlConnection))
  8. {
  9.  
  10. cmdCreateITableSP.CommandType = CommandType.StoredProcedure;
  11. cmdCreateTableSP.ExecuteNonQuery();
  12.  
  13. }
  14.  
  15. string INTable = "IN";
  16. string XMLPackagesDir = "D:\Cle\";
  17. // Create a datatable with two columns:
  18. DataTable INHReponseDT = new DataTable("INHReponseDT");
  19.  
  20. // Create Columns:
  21. INHReponseDT.Columns.Add("XM");
  22. INHReponseDT.Columns.Add("Cl");
  23. INHReponseDT.Columns.Add("I");
  24. INHReponseDT.Columns.Add("INH");
  25. INHReponseDT.Columns.Add("IN");
  26.  
  27.  
  28. DirectoryInfo DirInfo = new DirectoryInfo(XMLPackagesDir);
  29.  
  30. DataRow INHReponseRow = INHReponseDT.NewRow();
  31.  
  32. foreach (FileInfo fi in DirInfo.GetFiles("*.*", SearchOption.AllDirectories))
  33. {
  34. XmlSerializer serializer = new XmlSerializer(typeof(Response));
  35. Response i;
  36. FileStream fs = null;
  37. fs = new FileStream(Path.Combine(XMLPackagesDir, fi.Name), FileMode.Open);
  38.  
  39. using (TextReader tr = new StreamReader(fs))
  40. {
  41. i = (Response)serializer.Deserialize(tr);
  42. INHReponseRow = INHReponseDT.NewRow();
  43. INHReponseRow["XM"] = fi.Name;
  44. INHReponseRow["Cl"] = i.ClientCorrelationID;
  45. INHReponseRow["I"] = i.StatusInformation.StatusItem.MessageText;
  46. INHReponseRow["INH"] = i.ResponseStatus;
  47. INHReponseRow["IN"] = i.RequestProcessedTime.ToString();
  48.  
  49.  
  50.  
  51. INHReponseDT.Rows.Add(INHReponseRow);
  52. }
  53.  
  54. //Insert into SQL Table
  55. using (SqlBulkCopy s = new SqlBulkCopy(SqlConnection))
  56. {
  57.  
  58. s.DestinationTableName = INTable;
  59. s.BatchSize = INHReponseDT.Rows.Count;
  60. s.WriteToServer(INHReponseDT);
  61.  
  62.  
  63. s.Close();
  64.  
  65. }
  66.  
  67. }
  68.  
  69. using (SqlCommand cmdUpdateCaseInformationINHResponseSP = new SqlCommand("UpdateCaseSP", SqlConnection))
  70. {
  71. cmdUpdateCaseInformationINHResponseSP.CommandType = CommandType.StoredProcedure;
  72. cmdUpdateCaseInformationINHResponseSP.ExecuteNonQuery();
  73. }
  74.  
  75.  
  76.  
  77.  
  78. }
  79.  
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement