-
Notifications
You must be signed in to change notification settings - Fork 0
/
Function.cs
54 lines (52 loc) · 1.67 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
namespace Project
{
class Function
{
protected SqlConnection getConnection()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=DESKTOP-IOGAUF0\\SQLEXPRESS;Initial Catalog=myHotel;Integrated Security=True";
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,string message)
{
SqlConnection con = getConnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = query;
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show(" '" + message + "' ", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public SqlDataReader getForCombo(string query)
{
SqlConnection con = getConnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd = new SqlCommand(query, con);
SqlDataReader sdr = cmd.ExecuteReader();
return sdr;
}
}
}