Berikut ini contoh source yang dibuat untuk program VB 6, VB.net, dan C. Source ini berdasarkan pengalaman penulis dalam membuat aplikasi. Jadi sudah teruji,heheheheeee (bangga).... Database yang digunakan bisa apa saja, tergantung Anda.. semoga bermanfaat bagi kalian...
Adapun contoh source bisa dilihat di bawah ini...
a. Source VB 6 untuk menghubungkan database
'Koneksi
Public cn As New ADODB.Connection
'Recordset
Public rs As New ADODB.Recordset
Public Sub koneksi(ByVal konek As ADODB.Connection)
sprovider = "provider =Microsoft.Jet.OLEDB.4.0;"
db = "Data Source=" & App.Path & "\NAMA_DATABASE.mdb"
skon = sprovider & db
With konek
.CursorLocation = adUseClient
.Open skon
End With
End Sub
Public Sub Hubung_koneksi(sql_koneksi As String, c As ADODB.Connection, r As ADODB.Recordset)
With r
.CursorType = adOpenStatic
.LockType = adLockPessimistic
.Source = sql_koneksi
.ActiveConnection = c
.Open
End With
End Sub
Source diatas digunakan jika menggunakan cara manual... Jika menggunakan ODBC bisa dilihat pada prosedur di bawah ini.
Public Sub koneksi(ByVal konek As ADODB.Connection)
Dim sprovider As String
sprovider = "DRIVER=MySQL ODBC 3.51 Driver;" & _
"SERVER=localhost;" & _
"DATABASE=NAMA_DATABASE;" & _
"UID=root;" & _
"PASSWORD=;OPTION=;STMT=;"
With konek
.CursorLocation = adUseClient
.Open sprovider
End With
End Sub
b. Source VB.net untuk menghubungkan database
Public stringConnection As String
Public MyDataSource As String
Public MyUserID As String
Public MyPassword As String
Public strConnectInformation As String
'==WITH ODBC NET============================
Public Sub Koneksi(ByVal uid As String, ByVal pass As String, ByVal dtbase As String, ByVal server As String)
'connect to MySQL server using MySQL ODBC 3.51 Driver
conn = New ADODB.Connection
conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=192.168.1.55;" & _
"DATABASE=dt_sipkb;" & _
"UID=root2;" & _
"PASSWORD=root;" & _
"OPTION=3;"
Try
conn.Open()
Catch e As Exception
MsgBox(e.Message)
End Try
End Sub
c. Source C untuk menghubungkan database
MYSQL *conn,*conn1;
MYSQL_ROW row;
void connect_dt(char *fl)
{ char *dtconfig[8],flg,port=0,flags=0,i,flgof=0;
for (i=0;i<7;i++) {
dtconfig[i]=(char *)calloc(101,sizeof(char));
}
conn=mysql_init(NULL);
if (conn==NULL) {
fprintf(stderr,"mysql_init() failed\n");
flgconn=0;
}
else {
printf("CONNECT TO MYSQL : SUCCESS!!!\n");
flgconn=1;
}
flgof=open_file(dtconfig,fl,port,flags);
printf("dtconfig:[%s] [%s] [%s] [%s]\n", dtconfig[0],dtconfig[1],dtconfig[2],dtconfig[3]);
if (flgof) {
flg=0;
conn=mysql_real_connect(conn,dtconfig[0],dtconfig[1],dtconfig[2],dtconfig[3],port,dtconfig[5],flags);
if (conn==NULL) {
fprintf(stderr,"CAN'T CONNECT TO DATABASE %s\nflgcon0
mysql_real_connect() failed:\nError %u
(%s)\n",dtconfig[3],mysql_errno(conn),mysql_error(conn));
flgconn=0;
}
else {
printf("CONNECT TO DATABASE %s : SUCCESS!!!\n",dtconfig[3]);
flgconn=1;
}
}
else {
printf("something error in file %s or file %s NULL\n",fl,fl);
flgconn=0;
}
mysql_close(conn);
for (i=0;i<7;i++) {
free(dtconfig[i]);
}
}
Semua source di atas, dapat Anda kembangkan sesuai dengan kebutuhan Anda.. Jika ada pertanyaan silakan isi komentar ...