Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (SqlConnection SqlConnection = new SqlConnection(connectionString))
- {
- SqlConnection.Open();
- using (SqlCommand cmdCreateINHResponseTableSP = new SqlCommand("CreateSP", SqlConnection))
- {
- cmdCreateITableSP.CommandType = CommandType.StoredProcedure;
- cmdCreateTableSP.ExecuteNonQuery();
- }
- string INTable = "IN";
- string XMLPackagesDir = "D:\Cle\";
- // Create a datatable with two columns:
- DataTable INHReponseDT = new DataTable("INHReponseDT");
- // Create Columns:
- INHReponseDT.Columns.Add("XM");
- INHReponseDT.Columns.Add("Cl");
- INHReponseDT.Columns.Add("I");
- INHReponseDT.Columns.Add("INH");
- INHReponseDT.Columns.Add("IN");
- DirectoryInfo DirInfo = new DirectoryInfo(XMLPackagesDir);
- DataRow INHReponseRow = INHReponseDT.NewRow();
- foreach (FileInfo fi in DirInfo.GetFiles("*.*", SearchOption.AllDirectories))
- {
- XmlSerializer serializer = new XmlSerializer(typeof(Response));
- Response i;
- FileStream fs = null;
- fs = new FileStream(Path.Combine(XMLPackagesDir, fi.Name), FileMode.Open);
- using (TextReader tr = new StreamReader(fs))
- {
- i = (Response)serializer.Deserialize(tr);
- INHReponseRow = INHReponseDT.NewRow();
- INHReponseRow["XM"] = fi.Name;
- INHReponseRow["Cl"] = i.ClientCorrelationID;
- INHReponseRow["I"] = i.StatusInformation.StatusItem.MessageText;
- INHReponseRow["INH"] = i.ResponseStatus;
- INHReponseRow["IN"] = i.RequestProcessedTime.ToString();
- INHReponseDT.Rows.Add(INHReponseRow);
- }
- //Insert into SQL Table
- using (SqlBulkCopy s = new SqlBulkCopy(SqlConnection))
- {
- s.DestinationTableName = INTable;
- s.BatchSize = INHReponseDT.Rows.Count;
- s.WriteToServer(INHReponseDT);
- s.Close();
- }
- }
- using (SqlCommand cmdUpdateCaseInformationINHResponseSP = new SqlCommand("UpdateCaseSP", SqlConnection))
- {
- cmdUpdateCaseInformationINHResponseSP.CommandType = CommandType.StoredProcedure;
- cmdUpdateCaseInformationINHResponseSP.ExecuteNonQuery();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement