Senin, 21 April 2014

cara menampilkan data ke datagridview dari sql server 2008 r2 vb.net

ni kodingnya..hheeeeu
Imports System.Data.SqlClient

Public Class barang_elektronik

Private Sub barang_komputer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
Dim da As SqlClient.SqlDataAdapter
    Dim ds As DataSet

    End Sub

Sub koneksi()
        Try
            conn = New SqlClient.SqlConnection("Data Source=DAGOENG-24\SQLEXPRESS;Initial Catalog=db_kantor;Integrated Security=True")

            conn.Open()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub


 Sub tampil()
        koneksi()

        Try
            da = New SqlClient.SqlDataAdapter("Select * from dbo.komputer order by 'Jenis' ", conn)
            ds = New DataSet

            da.Fill(ds, "dbo.komputer")
            DataGridView1.DataSource = ds.Tables(0)
        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try

    End Sub

 Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

        tampil()

    End Sub



selesaiiii.....

Tidak ada komentar:

Posting Komentar