Tuesday, February 22, 2011
Adding,delete and update data to database (vb.Net desktop application)
This case explained how to search,add,delete and update data record to database in vb.Net. Hope that can be help to learn about data in Vb.Net
Using serching in vb.Net
Adding data in vb.Net
Update data in vb.Net
Delete data in vb.Net
How to make data increment in vb.net
Using serching in vb.Net
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Classdatabase.tutupdatabase() Dim carinama As String Dim cariperusahaan As String carinama = InputBox("Masukkan nama Pelanggan : ", "Cari Nama Pelanggan") cariperusahaan = InputBox(" Masukkan nama perusahaan : ", "Cari Perusahaan") If (Len(Trim(carinama)) And Len(Trim(cariperusahaan))) = 0 Then Exit Sub Classdatabase.bukadatabase() Classdatabase.perintahsql.CommandType = CommandType.Text Classdatabase.perintahsql.CommandText = "SELECT * from anggota where nama = '" & carinama & "' and perusahaan='" & cariperusahaan & "'" Classdatabase.ketemu = Classdatabase.perintahsql.ExecuteReader If Classdatabase.ketemu.Read Then ComboBox1.Items.Clear() TextBox1.Text = Classdatabase.ketemu("IDuser") TextBox2.Text = Classdatabase.ketemu("nama") TextBox3.Text = Classdatabase.ketemu("alamat") ComboBox1.Text = Classdatabase.ketemu("kategori") If ComboBox1.Text = "tetap" Then ComboBox1.Items.Add("tidak tetap") Else ComboBox1.Items.Add("tetap") End If TextBox4.Text = Classdatabase.ketemu("perusahaan") TextBox5.Text = Classdatabase.ketemu("HP") Classdatabase.tutupdatabase() Else Classdatabase.tutupdatabase() MsgBox("Data Tidak Ditemukan", MsgBoxStyle.Information, "INFORMASI") kosong() End If End Sub |
Adding data in vb.Net
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Trim(TextBox1.Text.Length) = 0 Or Trim(TextBox2.Text.Length) = 0 Or Trim(TextBox3.Text.Length) = 0 Or Trim(TextBox4.Text.Length) = 0 Or Trim(ComboBox1.SelectedIndex) = -1 Then MsgBox("Data Belum Lengkap", 48, "Informasi") Else Classdatabase.bukadatabase() Classdatabase.perintahsql.CommandText = "INSERT INTO anggota values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & ComboBox1.Text & "','" & TextBox5.Text & "')" Classdatabase.perintahsql.ExecuteNonQuery() Classdatabase.tutupdatabase() MsgBox("Data Telah Disimpan", 64, "Informasi") kosong() End If End Sub |
Update data in vb.Net
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Classdatabase.tutupdatabase() Classdatabase.bukadatabase() Classdatabase.perintahsql.CommandText = "UPDATE anggota set nama = '" & TextBox2.Text & "', alamat = '" & TextBox3.Text & "', perusahaan = '" & TextBox4.Text & "', kategori = '" & ComboBox1.Text & "', HP = '" & TextBox5.Text & "' where IDuser='" & TextBox1.Text & "'" Classdatabase.perintahsql.ExecuteNonQuery() Classdatabase.tutupdatabase() MsgBox("Data Telah Diperbaiki!", MsgBoxStyle.Information, "INFORMASI") kosong() ComboBox1.Items.Clear() End Sub |
Delete data in vb.Net
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 'Tombol HAPUS DATA Classdatabase.tutupdatabase() Classdatabase.bukadatabase() Classdatabase.perintahsql.CommandText = "DELETE * from anggota where IDuser = '" & TextBox1.Text & "'" Classdatabase.perintahsql.ExecuteNonQuery() Classdatabase.tutupdatabase() MsgBox("Data Telah Dihapus!!", MsgBoxStyle.Information, "INFORMASI") kosong() End Sub |
How to make data increment in vb.net
Private Sub Formtambah2_Activated1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated 'Membuat nomor ID member TextBox1.Enabled = False Classdatabase.bukadatabase() Classdatabase.perintahsql.CommandText = "SELECT top 1 right(IDuser,4)+1 as IDuser from anggota order by IDuser desc" Classdatabase.ketemu = Classdatabase.perintahsql.ExecuteReader If Classdatabase.ketemu.Read Then Select Case Classdatabase.ketemu("IDuser") Case Is <= 9 : ID = "P000" & Classdatabase.ketemu("IDuser") Case Is <= 99 : ID = "P00" & Classdatabase.ketemu("IDuser") Case Is <= 999 : ID = "P0" & Classdatabase.ketemu("IDuser") Case Else : ID = "P" & Classdatabase.ketemu("IDuser") End Select Else ID = "P0001" End If Classdatabase.tutupdatabase() TextBox1.Text = ID End Sub |
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