Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public DataTable makeTherapyStatusTransitionTable()
- // Create a new DataTable named NewProducts.
- {
- DataTable tstTable = new DataTable("therapystatustransition");
- DataColumn therapy = new DataColumn();
- therapy.DataType = System.Type.GetType("System.Int32");
- therapy.ColumnName = "therapy";
- tstTable.Columns.Add(therapy);
- DataColumn minutes = new DataColumn();
- minutes.DataType = System.Type.GetType("System.String");
- minutes.ColumnName = "minutes";
- tstTable.Columns.Add(minutes);
- DataColumn seconds = new DataColumn();
- seconds.DataType = System.Type.GetType("System.String");
- seconds.ColumnName = "seconds";
- tstTable.Columns.Add(seconds);
- DataColumn time = new DataColumn();
- time.DataType = System.Type.GetType("System.DateTime");
- time.ColumnName = "time";
- tstTable.Columns.Add(time);
- DataColumn from_phase = new DataColumn();
- from_phase.DataType = System.Type.GetType("System.Int32");
- from_phase.ColumnName = "from_phase";
- tstTable.Columns.Add(from_phase);
- DataColumn to_phase = new DataColumn();
- to_phase.DataType = System.Type.GetType("System.Int32");
- to_phase.ColumnName = "to_phase";
- tstTable.Columns.Add(to_phase);
- return tstTable;
- }
- public string bulkTableTo(DataTable dataTable, string tabellenname)
- {
- // get your connection string
- string connString = MyConfigurationManager.prdSqlServerString;
- // connect to SQL
- using (SqlConnection connection = new SqlConnection(connString))
- {
- // make sure to enable triggers
- // more on triggers in next post
- SqlBulkCopy bulkCopy = new SqlBulkCopy
- (
- connection,
- SqlBulkCopyOptions.Default,
- null
- );
- // set the destination table name
- bulkCopy.DestinationTableName = tabellenname;
- connection.Open();
- // write the data in the "dataTable"
- try
- {
- bulkCopy.WriteToServer(dataTable);
- }
- catch (Exception e)
- {
- return "Es ist ein Fehler aufgetreten. " +
- "Stellen Sie sicher dass der Timeout im SQL Server " +
- "auf unendlich steht und AutoClose für die Verbindung " +
- "nicht aktiviert wurde. " + e.Message;
- }
- connection.Close();
- }
- // reset
- dataTable.Clear();
- return "ok";
- }
- string[] phasenInfo = inputLine.Split(new Char[] { ' ' });
- //string[] phasenRow = new string[] { Int32.Parse(therapy_id), phasenInfo[0], phasenInfo[1], UnixTimeStampToDateTime(Double.Parse(phasenInfo[2])).ToString(), phasenInfo[3], phasenInfo[4] };
- DataRow row = historyTable.NewRow();
- row["therapy"] = Int32.Parse(therapy_id);
- row["minutes"] = phasenInfo[0];
- row["seconds"] = phasenInfo[1];
- row["time"] = UnixTimeStampToDateTime(Double.Parse(phasenInfo[2]));
- row["from_phase"] = Int32.Parse(phasenInfo[3]);
- row["to_phase"] = Int32.Parse(phasenInfo[4]);
- historyTable.Rows.Add(row);
Add Comment
Please, Sign In to add comment