-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlClient.cs
More file actions
65 lines (61 loc) · 2.11 KB
/
Copy pathSqlClient.cs
File metadata and controls
65 lines (61 loc) · 2.11 KB
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
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace RADARMRM
{
class SqlClient
{
SqlConnection connection;
SqlCommand command = new SqlCommand();
Form1 ui;
public SqlClient(Form1 ui, string sqlConnectionString)
{
this.ui = ui;
connection = new SqlConnection(sqlConnectionString);
try
{
connection.Open();
command.Connection = connection;
command.Parameters.Add("@time", SqlDbType.SmallDateTime);
command.Parameters.Add("@overall", SqlDbType.NChar);
command.Parameters.Add("@radar", SqlDbType.NChar);
command.Parameters.Add("@vibration", SqlDbType.NChar);
command.Parameters.Add("@licensePlate", SqlDbType.NChar);
command.CommandText = "INSERT INTO result (time, ALARM_overall, ALARM_radar, ALARM_vibration, licensePlate) Values (@time, @overall, @radar, @vibration, @licensePlate)";
}
catch(Exception e)
{
ui.UpdateStatus(e.Message);
}
}
public void Insert(string overall, string radar, string vibration, string licensePlate)
{
try
{
command.Parameters[0].Value = DateTime.Now;
command.Parameters[1].Value = overall;
if (radar == null)
command.Parameters[2].Value = DBNull.Value;
else
command.Parameters[2].Value = radar;
if (vibration == null)
command.Parameters[3].Value = DBNull.Value;
else
command.Parameters[3].Value = vibration;
command.Parameters[4].Value = licensePlate;
command.ExecuteNonQuery();
}
catch(Exception e)
{
ui.UpdateStatus(e.Message);
}
}
public void Close()
{
connection.Close();
}
}
}