-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigdb.cs
65 lines (54 loc) · 1.65 KB
/
configdb.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
namespace SistemBarang
{
public class configdb
//aim : create sql connection, run a query,
{
public OleDbConnection koneksi;
public configdb()
{
this.koneksi = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|tugasweb.accdb");
}
public void OpenConnection()
{
try
{
this.koneksi.Open();
System.Diagnostics.Debug.WriteLine("BERHASIL TERKONEKSI!");
}
catch (InvalidOperationException)
{
System.Diagnostics.Debug.WriteLine("GAGAL TERKONEKSI!");
}
}
public void CloseConnection()
{
try
{
this.koneksi.Close();
}
catch (InvalidOperationException)
{
System.Diagnostics.Debug.WriteLine("Koneksi sudah tidak terhubung");
}
}
public OleDbDataReader openQuerySQL(string queryF)
{
//Membuat SQLCommand menggunakan Query dan Koneksi yang telah ditentukan
OleDbCommand comm = new OleDbCommand(queryF, this.koneksi);
//Menghubungkan Koneksi tersebut
this.OpenConnection();
//Mengexecute SQLCommand dan me-Retrieve data
OleDbDataReader resultsF = comm.ExecuteReader();
//Jika Ada Data(Ketemu)}
return resultsF;
}
}
}