loading...

loading...

Hai Gais kali ini admin mau berbagi cara membuat master detail di Gridview ,

Admin mau buat 2 cara , pertama master detail dengan database , kedua tanpa database. nanti silahkan kembangkan lagi sesuai kondisi kalian .

seperti biasa kalo admin bikin koneksinya pke module , admin pake database mysql dan pakai referensi file mysql.data,
ini codingnya geks…………

Imports MySql.Data.MySqlClient
Module Koneksi
Public str As String
Public str1 As String
Public con As MySqlConnection
Public da As MySqlDataAdapter
Public da1 As MySqlDataAdapter
Public ds As DataSet
Public cmd As MySqlCommand

Public con_server As String = "localhost"
Public con_userid As String = "root"
Public con_password As String = ""
Public con_database As String = "kedaicat"

Public Sub BukaDB()
Try
str = "Server =" & con_server & ";User Id=" & con_userid & "; password=" & con_password & ";database=" & con_database & ""
con = New MySqlConnection(str)

If con.State = ConnectionState.Closed Then
con.Open()
MsgBox("Koneksi Sukses")
' sts = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub
End Module

lalu di form1 , kita buat codingan untuk menampilkan master detailnya. kalo admin bikin function name nya GetMaster1

Public Sub GetMaster1()
BukaDB()

'query get notabeli
str = " select NOTA,DISCGLOBAL,GRANDTOTAL,TGLJTHTEMPO from notabeli"

'query get listbeli
str1 = "select RECNO,CREATED,NOTA,stockid,QTY,HSATUAN,`DISC%`,TOTAL from listbeli"

'add query notabeli ke dataadapter
da = New MySqlDataAdapter(str, con)

'add query lisbeli ke dataadapter
da1 = New MySqlDataAdapter(str1, con)

'deklarsi dtm = datatable
dtM = New DataTable

'deklarsi dtd = datatable
dtd = New DataTable

'deklarsi ds = dataset
ds = New DataSet

'add dataadpter query notabeli ke ds
da.Fill(ds, "notabeli")

'insert data ds ke dtm
dtM = ds.Tables("notabeli")

'add primery key data dtM "OPTIONAL"
dtM.PrimaryKey = New DataColumn() {dtM.Columns("NOTA")}

'add dataadpter query listbeli ke ds
da1.Fill(ds, "listbeli")

'insert data ds ke dtd
dtd = ds.Tables("listbeli")

'add primery key dan foregn key data dtd "OPTIONAL"
dtd.PrimaryKey = New DataColumn() {dtd.Columns("RECNO"), dtd.Columns("NOTA")}

'Create Relasi dtm dan dtd masukan dalam dataset
Dim Relasi As New DataRelation("Master Detail", dtM.Columns("NOTA"), dtd.Columns("NOTA"))
ds.Relations.Add(Relasi)

'get dtM ke Grid data source
GridControl1.DataSource = dtM

GridView1.OptionsBehavior.Editable = False
End Sub

nah ini sudah kelar , coba function tadi di masukan ke button click. lalu coba running . pasti work…….

MEMBUAT MASTER DETAIL GRID VIEW (VBNET)
Share This
FacebookTwitterGoogle+WhatsAppEmailPrintFriendly
loading...

Post navigation


Leave a Reply

Your email address will not be published. Required fields are marked *