Sudah lama tidak posting, menjelang akhir tahun akan memposting Cara Menyimpan Data ke Dalam Database VB.NET.
Langsung aja masuk ke pembuatannya ::
source code programnya ::
Panggil source code diatas ti button simpan source code ::
Langsung aja masuk ke pembuatannya ::
source code programnya ::
Sub
MDBK_SIMPAN_DATA()
Konek()
SQL1 = "select
* from BARANG where KODE ='" & tkode.Text & "' "
Using
cmd As New
OleDbCommand(SQL1, Conn)
Using
baca As OleDbDataReader = cmd.ExecuteReader
baca.Read()
If
Not baca.HasRows Then
Call
Konek()
SQL1 = "insert into BARANG
(KODE,NAMA,KELOMPOK,SATUAN,JUMLAH,HARGA)values('" & tkode.Text
& "','" & tnama.Text &
"','" & tkelompok.Text & "','" & tsatuan.Text & "','" & tjumlah.Text & "','" & tharga.Text & "')"
Using
cmdd = New OleDbCommand(SQL1, Conn)
cmdd.ExecuteNonQuery()
MsgBox("Data Sudah Disimpan",
MsgBoxStyle.Information, "Perhatian")
End
Using
Conn.Close()
Else
Call
Konek()
Dim
ubahdata As String
= "update BARANG set KODE='" &
tkode.Text & "',NAMA='" &
tnama.Text & "',KELOMPOK='"
& tkelompok.Text & "',SATUAN='"
& tsatuan.Text & "',JUMLAH='"
& tjumlah.Text & "',HARGA='"
& tharga.Text & "'where KODE ='"
& tkode.Text & "' "
Using
cmde = New OleDbCommand(ubahdata, Conn)
cmde.ExecuteNonQuery()
MsgBox("Data Sudah Diubah",
MsgBoxStyle.Information, "Perhatian")
End
Using
Conn.Close()
End
If
Conn.Close()
End
Using
End Using
End Sub
Panggil source code diatas ti button simpan source code ::
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If
tkode.Text = "" Or tnama.Text = ""
Or tsatuan.Text = ""
Or tkelompok.Text = ""
Or tjumlah.Text = ""
Or tharga.Text = ""
Then
MsgBox("Lengkapi
Data yang Akan Disimpan", MsgBoxStyle.Critical, "Perhatian")
Else
Call
MDBK_SIMPAN_DATA()
End If
End Sub
::Selamat mencoba, silahkan tinggalkan komentar jika ada yang mau ditanyakan ::
0 komentar:
Posting Komentar