-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDbWriter.cs
55 lines (40 loc) · 1.47 KB
/
DbWriter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using log4net;
using log4net.Config;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DbOperator
{
class DbWriter
{
private static readonly log4net.ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public void writeToDb(TestResult tr)
{
Console.WriteLine(tr.actualResult);
Console.WriteLine(tr.endTime);
Console.WriteLine(tr.executionStatus);
Console.WriteLine(tr.failureReason);
XmlConfigurator.Configure();
string str = "Data Source=DESKTOP-FL8HUKR\\SQLEXPRESS;Initial Catalog=CompanyDb;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
con.Open();
using (con)
{
try
{
SqlCommand command2 = new SqlCommand("Insert into TestResult values('"+tr.actualResult+"','"+tr.executionStatus+"','"+tr.startTime+"','"+tr.endTime+"','"+tr.failureReason+"')", con);
command2.ExecuteNonQuery();
}
catch (Exception ex)
{
_log.Error(ex);
}
}
Console.ReadKey();
}
}
}