Tuesday, February 22, 2011
Connected Database in VB.Net (desktop application)
In this case I want to tell about how to connet database in Vb.Net using Ms.Access and SQl Server. This is the example coding that is use to connect database:
Using Ms.Access
Using SQL SERVER
Using Ms.Access
Public Class klasku Public Shared koneksi As New OleDb.OleDbConnection Public Shared perintahsql As New OleDb.OleDbCommand Public Shared da As New OleDb.OleDbDataAdapter Public Shared ds As New DataSet Public Shared ds2 As New DataSet Public Shared ds3 As New DataSet Public Shared ketemu As OleDb.OleDbDataReader Public Shared Sub bukadatabase() Try koneksi.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=f:\vb2\prjbuku\dbgemilang.accdb" koneksi.Open() perintahsql.Connection = koneksi Catch ex As Exception MsgBox("Koneksi Gagal" & Chr(13) & ex.Message, 16, "Error") End Try End Sub Public Shared Sub tutupdatabase() koneksi.Close() koneksi.ConnectionString = Nothing End Sub Public Shared Sub close() Dim tanya As String tanya = MessageBox.Show("Apakah Anda Ingin Keluar?", "Informasi", MessageBoxButtons.YesNo, MessageBoxIcon.Information) If tanya = vbYes Then End Else MessageBox.Show("Selamat Bekerja", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub End Class |
Using SQL SERVER
Public Class Klasku Private Shared koneksi As New SqlClient.SqlConnection Public Shared PerintahSQL As New SqlClient.SqlCommand Public Shared ds2 As New DataSet Public Shared da As New SqlClient.SqlDataAdapter Public Shared ds As New DataSet 'objek ketemu tidak memerlukan view Public Shared ketemu As SqlClient.SqlDataReader Public Shared Sub BUKADATABASE() Try koneksi.ConnectionString = "Data Source=.\sqlexpress;Initial Catalog=dbuas;Integrated Security=True" koneksi.Open() PerintahSQL.Connection = koneksi Catch ex As Exception MsgBox("Koneksi Ke Database Gagal" & Chr(13) & ex.Message, 16, "EROR") End Try End Sub Public Shared Sub TUTUPDATABASE() koneksi.Close() koneksi.ConnectionString = Nothing End Sub End Class |
This post was written by: Yung Fei
Follow me on My Twitter and like my Online Coupons fans page
- Best Regard -
OnlineCouponz
Fresh Printable Coupons
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment