-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBoperation.cs
139 lines (128 loc) · 3.33 KB
/
DBoperation.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DBoperation
/// </summary>
public class DBoperation
{
public SqlConnection con;
public SqlCommand cmd;
public DBoperation()
{
con = new SqlConnection("Data Source=.;Initial Catalog=order;Integrated Security=True");
cmd = new SqlCommand();
cmd.Connection = con;
}
public SqlConnection getcon()
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
return con;
}
public void dbclose()
{
con.Close();
}
public int exenonquery(String sql)
{
getcon();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
int i = cmd.ExecuteNonQuery();
return i;
}
public object exescalar(String sql)
{
getcon();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
object ob = cmd.ExecuteScalar();
return ob;
}
public SqlDataReader exereader(String sql)
{
getcon();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
SqlDataReader dr = cmd.ExecuteReader();
return dr;
}
public DataSet exedataset(String sql)
{
// cmd.Connection = getcon();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
public DataTable exetable(String sql)
{
//cmd.Connection = getcon();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public void fillgrid(String sql, GridView dv)
{
dv.DataSource = exedataset(sql);
dv.DataBind();
}
public void filldlist(String sql, DataList dl)
{
dl.DataSource = exedataset(sql);
dl.DataBind();
}
public void filldetailsview(String sql, DetailsView dv)
{
dv.DataSource = exedataset(sql);
dv.DataBind();
}
public void filllistview(String sql, ListView dl)
{
dl.DataSource = exedataset(sql);
dl.DataBind();
}
public void formfill(String sql, FormView fl)
{
fl.DataSource = exedataset(sql);
fl.DataBind();
}
public void fillddl(String sql, DropDownList ddl, String txt, String val)
{
ddl.DataTextField = txt;
ddl.DataValueField = val;
ddl.DataSource = exedataset(sql);
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("---select---", "0"));
}
public void fillrbl(String sql, RadioButtonList rbl, String txt, String val)
{
rbl.DataTextField = txt;
rbl.DataValueField = val;
rbl.DataSource = exedataset(sql);
rbl.DataBind();
}
public void exec_sp(SqlCommand cmd1)
{
cmd1.Connection = con;
con.Open();
cmd1.ExecuteNonQuery();
}
}