-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataAccess.cs
104 lines (88 loc) · 2.58 KB
/
DataAccess.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
namespace WindowsFormsHotelManagement
{
class DataAccess
{
private SqlConnection sqlcon;
public SqlConnection Sqlcon
{
get { return this.sqlcon; }
set { this.sqlcon = value; }
}
private SqlCommand sqlcom;
public SqlCommand Sqlcom
{
get { return this.sqlcom; }
set { this.sqlcom = value; }
}
private SqlDataAdapter sda;
public SqlDataAdapter Sda
{
get { return this.sda; }
set { this.sda = value; }
}
private DataSet ds;
public DataSet Ds
{
get { return this.ds; }
set { this.ds = value; }
}
//internal DataTable dt;
public DataAccess()
{
this.Sqlcon = new SqlConnection(@"Data Source=DESKTOP-8F6OULV\SQLEXPRESS;Initial Catalog=hotel;Integrated Security=True");
this.Sqlcon.Open();
}
private void QueryText(string query)
{
this.Sqlcom = new SqlCommand(query, this.Sqlcon);
}
public DataSet ExecuteQuery(string sql)//get data from data base
{
try
{
this.QueryText(sql);
this.Sda = new SqlDataAdapter(this.Sqlcom);
this.Ds = new DataSet();
this.Sda.Fill(this.Ds);
return this.Ds;
}
catch (Exception exc)
{
return null;
}
}
public DataTable ExecuteQueryTable(string sql)
{
this.ExecuteQuery(sql);
if (this.Ds != null)
return this.Ds.Tables[0];
else
return null;
}
public void ExecuteUpdateQuery(string sql)
{
this.QueryText(sql);
this.Sqlcom.ExecuteNonQuery();
}
public SqlDataReader FetchData(string query)
{
DataAccess da = new DataAccess();
this.QueryText(query);
SqlDataReader sdr = this.sqlcom.ExecuteReader();
return sdr;
}
/* public void SetData(string query)
{
SqlConnection con = this.Sqlcon;
SqlCommand cmd= this
}*/
}
}