/
Connection.cs
71 lines (61 loc) · 1.71 KB
/
Connection.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace TAYFUNADAKOGLU
{
class Connection
{
string str;
SqlConnection cnn;
SqlCommand cmd;
SqlDataAdapter adapter;
public Connection()
{
str = "Server=TADAKOGLU\\SERVER;Database=BUSDB;Trusted_Connection=True";
//str = "Data Source = TADAKOGLU\\SERVER; Initial Catalog = BUSDB; Integrated Security = True";
}
public DataTable gettb(string command)
{
DataTable table = new DataTable();
cnn = new SqlConnection(str);
cmd = new SqlCommand(command, cnn);
adapter = new SqlDataAdapter(cmd);
adapter.Fill(table);
return table;
}
public bool control(string cmd)
{
DataTable tb;
tb = gettb(cmd);
if (tb.Rows.Count > 0)
return true;
return false;
}
public bool runcmd(string command)
{
cnn = new SqlConnection(str);
cmd = new SqlCommand(command,cnn);
int rowsaffacted = 0;
try
{
cnn.Open();
rowsaffacted = cmd.ExecuteNonQuery();
}
catch
{
rowsaffacted = -1;
}
finally
{
cnn.Close();
}
if (rowsaffacted != -1)
return true;
return false;
}
}
}