This repository was archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDatabaseHelper.cs
More file actions
74 lines (69 loc) · 2.01 KB
/
DatabaseHelper.cs
File metadata and controls
74 lines (69 loc) · 2.01 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
66
67
68
69
70
71
72
73
74
using System;
using System.Data;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Windows.Forms;
namespace DevPro_CardManager
{
public static class DatabaseHelper
{
public static SQLiteCommand CreateCommand(string statement, SQLiteConnection connection)
{
return new SQLiteCommand
{
CommandText = statement,
CommandType = CommandType.Text,
Connection = connection
};
}
public static bool ExecuteNonCommand(SQLiteCommand command)
{
try
{
command.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
public static List<string[]> ExecuteStringCommand(SQLiteCommand command, int columncount)
{
try
{
var values = new List<string[]>();
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
var row = new List<string>();
for(int i = 0;i < reader.FieldCount; i++)
{
row.Add(reader[i].ToString());
}
values.Add(row.ToArray());
}
reader.Close();
return values;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return new List<string[]>();
}
}
public static int ExecuteIntCommand(SQLiteCommand command)
{
try
{
return Convert.ToInt32(command.ExecuteScalar());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return -1;
}
}
}
}