-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataService.cs
51 lines (38 loc) · 1.62 KB
/
DataService.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Excell
{
class DataService
{
private static string dbConnectionString = @"Server=DESKTOP-LGFTI19\SQLEXPRESS; Database=KeyValues; Trusted_Connection=True;";
internal static DataTable GetFields()
{
SqlConnection connection = new SqlConnection(dbConnectionString);
string sql = "SELECT * FROM Fields";
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
DataTable fieldsTable = new DataTable();
adapter.Fill(fieldsTable);
return fieldsTable;
}
internal static void AddField(string UID, string fieldType, string fieldKey, string fieldValue)
{
using (SqlConnection connection = new SqlConnection(dbConnectionString))
{
String query = "INSERT INTO Fields (UID,ObjectType, FieldKey, FieldValue)" +
" VALUES (@UID, @ObjectType, @FieldKey, @FieldValue)";
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.AddWithValue("@UID", UID);
command.Parameters.AddWithValue("@ObjectType", fieldType);
command.Parameters.AddWithValue("@FieldKey", fieldKey);
command.Parameters.AddWithValue("@FieldValue", fieldValue);
connection.Open();
command.ExecuteNonQuery();
}
}
}
}
}