-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.cs
58 lines (56 loc) · 1.7 KB
/
function.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
56
57
58
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Cafe_Management_System
{
internal class function
{
private SqlConnection _connection;
private string connectionString = "Server=DESKTOP-68U66QP\\MSSQLSERVER01;Initial Catalog=QCafe;Integrated Security=True";
protected SqlConnection getConnection()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = connectionString;
return con;
}
public DataSet getData(String query)
{
SqlConnection con = getConnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = query;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
public void setData(String query)
{
SqlConnection con = getConnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = query;
cmd.ExecuteNonQuery();
con.Close();
}
public SqlCommand getInstance()
{
_connection = new SqlConnection(connectionString);
_connection.Open();
SqlCommand command = new SqlCommand();
command.Connection = _connection;
return command;
}
public void closeInstance()
{
_connection.Close();
}
}
}