Guest User

Untitled

a guest
Mar 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. public DataTable makeTherapyStatusTransitionTable()
  2. // Create a new DataTable named NewProducts.
  3. {
  4. DataTable tstTable = new DataTable("therapystatustransition");
  5.  
  6. DataColumn therapy = new DataColumn();
  7. therapy.DataType = System.Type.GetType("System.Int32");
  8. therapy.ColumnName = "therapy";
  9. tstTable.Columns.Add(therapy);
  10.  
  11. DataColumn minutes = new DataColumn();
  12. minutes.DataType = System.Type.GetType("System.String");
  13. minutes.ColumnName = "minutes";
  14. tstTable.Columns.Add(minutes);
  15.  
  16. DataColumn seconds = new DataColumn();
  17. seconds.DataType = System.Type.GetType("System.String");
  18. seconds.ColumnName = "seconds";
  19. tstTable.Columns.Add(seconds);
  20.  
  21. DataColumn time = new DataColumn();
  22. time.DataType = System.Type.GetType("System.DateTime");
  23. time.ColumnName = "time";
  24. tstTable.Columns.Add(time);
  25.  
  26. DataColumn from_phase = new DataColumn();
  27. from_phase.DataType = System.Type.GetType("System.Int32");
  28. from_phase.ColumnName = "from_phase";
  29. tstTable.Columns.Add(from_phase);
  30.  
  31. DataColumn to_phase = new DataColumn();
  32. to_phase.DataType = System.Type.GetType("System.Int32");
  33. to_phase.ColumnName = "to_phase";
  34. tstTable.Columns.Add(to_phase);
  35.  
  36. return tstTable;
  37. }
  38.  
  39. public string bulkTableTo(DataTable dataTable, string tabellenname)
  40. {
  41. // get your connection string
  42. string connString = MyConfigurationManager.prdSqlServerString;
  43. // connect to SQL
  44. using (SqlConnection connection = new SqlConnection(connString))
  45. {
  46. // make sure to enable triggers
  47. // more on triggers in next post
  48.  
  49. SqlBulkCopy bulkCopy = new SqlBulkCopy
  50. (
  51. connection,
  52. SqlBulkCopyOptions.Default,
  53. null
  54. );
  55.  
  56. // set the destination table name
  57. bulkCopy.DestinationTableName = tabellenname;
  58. connection.Open();
  59.  
  60. // write the data in the "dataTable"
  61. try
  62. {
  63. bulkCopy.WriteToServer(dataTable);
  64. }
  65. catch (Exception e)
  66. {
  67. return "Es ist ein Fehler aufgetreten. " +
  68. "Stellen Sie sicher dass der Timeout im SQL Server " +
  69. "auf unendlich steht und AutoClose für die Verbindung " +
  70. "nicht aktiviert wurde. " + e.Message;
  71. }
  72. connection.Close();
  73. }
  74. // reset
  75. dataTable.Clear();
  76. return "ok";
  77. }
  78.  
  79. string[] phasenInfo = inputLine.Split(new Char[] { ' ' });
  80. //string[] phasenRow = new string[] { Int32.Parse(therapy_id), phasenInfo[0], phasenInfo[1], UnixTimeStampToDateTime(Double.Parse(phasenInfo[2])).ToString(), phasenInfo[3], phasenInfo[4] };
  81.  
  82. DataRow row = historyTable.NewRow();
  83. row["therapy"] = Int32.Parse(therapy_id);
  84. row["minutes"] = phasenInfo[0];
  85. row["seconds"] = phasenInfo[1];
  86. row["time"] = UnixTimeStampToDateTime(Double.Parse(phasenInfo[2]));
  87. row["from_phase"] = Int32.Parse(phasenInfo[3]);
  88. row["to_phase"] = Int32.Parse(phasenInfo[4]);
  89. historyTable.Rows.Add(row);
Add Comment
Please, Sign In to add comment