waduh mas pur,
saya terbiasa deklarasikan variabel

dim Rs as new adodb.recordset
dim con as new adodb.connection
kemudian,
di form_load jg:
set rs = new adodb.recordset
jadi, selama ini,saya boros donk..??
thanx for the info..

-agus-

--- Purwedi Kurniawan <[EMAIL PROTECTED]>
wrote:

> saya bukan guru mas, tapi biar jelas coba liat kode
> berikut:
> 
> Option Explicit
> 
> Private oConnection As ADODB.Connection     ' kalau
> kamu pake set new di
> form load, disini ga usah pake As New, kalau pake
> berarti kamu bikin object
> n mengalokasikan memori nya 2x, disini dan di form
> load, gunakan keyword
> Private or Public instead of Dim, biar jelas ruang
> lingkup variablenya.
> Private oRecordset As ADODB.Recordset       '
> gunakan naming convention yg
> jelas, biar kita tau ini object atau variable,
> typenya apa dll
> 
> Private Sub cmdTampilData_Click()
>     Call TampilData
> End Sub
> 
> Private Sub Form_Load()
>     Set oConnection = New ADODB.Connection
>     With oConnection
>         .CursorLocation = adUseClient
>         .Open "data"
>     End With
> End Sub
> 
> Public Sub TampilData()
>     Dim sSql As String  ' gunakan nama variable yg
> bisa dimengerti oleh
> orang lain, biar anggota team developer lain bisa
> baca
> 
>     sSql = "select * from tblbarang"
> 
>     Set oRecordset = New ADODB.Recordset
>     With oRecordset
>         .ActiveConnection = oConnection ' disini lah
> kita menggunakan
> koneksi yg tadi dibuka di form load, Adodc komponen
> sudah punya koneksi nya
> sendiri
>         .CursorType = adOpenForwardOnly
>         .Source = sSql
>         .Open
>     End With
> 
>     Set DataGrid1.DataSource = oRecordset
>     DataGrid1.Refresh
> End Sub
> 
> Private Sub Form_Unload(Cancel As Integer)
>     If oRecordset.State = adStateOpen Then
> oRecordset.Close ' percuma nutup
> object ini kalau dia dalam keadaan tertutup
>     Set oRecordset = Nothing
>     If oConnection.State = adStateOpen Then
> oConnection.Close
>     Set oConnection = Nothing
> End Sub
> 
> best regards
> [wwn]


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Wahana Programmer Groups Links

<*> Untuk mengunjungi sponsor milis ini, klik link berikut:
    http://wahanaprogrammer.net

<*> Untuk menghubungi owner milis ini, kirim email ke:
    [EMAIL PROTECTED]

<*> Konsultasi pemrogramman bisa chat disini:
    Yahoo! Messenger: wahanaprogrammer
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/Programmer-VB/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Kirim email ke