Code:
Public Class Form1 Dim cn As New Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=shreyas; User=root;Password=;") Dim cmd As Odbc.OdbcCommand Dim adp As Odbc.OdbcDataAdapter Dim ds As New DataSet Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing cn.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Fill the data grid viewer cn.Open() cmd = New Odbc.OdbcCommand("Select * from trial1", cn) adp = New Odbc.OdbcDataAdapter(cmd) adp.Fill(ds, "trial1") Me.DataGridView1.DataSource = ds Me.DataGridView1.DataMember = "trial1" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Update records using a Command Builder ' The variable i gives the number of records updated Dim cmdbuilder As New Odbc.OdbcCommandBuilder(adp) Dim i As Integer Try i = adp.Update(ds, "trial1") MsgBox("Records Updated= " & i) Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class
Gini gan..... Private Sub Frm_......._Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try DataGrid.DataSource = New DataTable() Dim DT As DataTable = DataGrid.DataSource DT.Columns.Add(New DataColumn("Columns1")) DT.Columns.Add(New DataColumn("Columms2")) Catch ex As Exception MessageBox.Show("Error : " & ex.Message, "Error Message") End Try End Sub Private Sub BtnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSimpan.Click Try With DataGrid Dim DT As DataTable = DataGrid.DataSource Dim NewRow As DataRow = DT.NewRow() NewRow("Columns1") = Txt_Columns1.Text NewRow("Columns2") = Txt_Columns2.Text DT.Rows.Add(NewRow) End With Call cleartexttonase() MessageBox.Show("Save Successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception MessageBox.Show("Error : " & ex.Message, "Error Message") End Try End Sub
1 komentar:
kalo di vb 6.0 gmn ya gan?
mohon pencerahannya..
Posting Komentar