- Beranda
- Komunitas
- Tech
- Programmer Forum
(ask) (vb2010) (sql Server 2005)


TS
dank01
(ask) (vb2010) (sql Server 2005)
sumpah da bingung ane om napa nie erornya kesalahan penulisan ane liat2 gak da .,'" lengkap semua...Mohon bantuanya om---
====================================
source code
====================================
Imports System.Data.SqlClient
Public Class CUSTOMER
Sub Kosongkan()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox1.Focus()
End Sub
Sub DataBaru()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox2.Focus()
End Sub
Sub TampilGrid()
Call Koneksi()
DA = New SqlDataAdapter("select * from TBLCUSTOMER", CONN)
DS = New DataSet
DA.Fill(DS)
DGV.DataSource = DS.Tables(0)
DGV.ReadOnly = True
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Koneksi()
Call TampilGrid()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
TextBox1.MaxLength = 10
If e.KeyChar = Chr(13) Then
Call Koneksi()
CMD = New SqlCommand("select * from TBLCUSTOMER where KODE_CUSTOMER='" & TextBox1.Text & "'", CONN)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows Then
TextBox2.Text = DR.Item("NAMA_CUSTOMER")
TextBox3.Text = DR.Item("ALAMAT_CUSTOMER")
TextBox4.Text = DR.Item("TELPON_CUSTOMER")
TextBox5.Text = DR.Item("CONTACT_PERSON")
TextBox2.Focus()
Else
Call DataBaru()
End If
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
TextBox2.MaxLength = 50
If e.KeyChar = Chr(13) Then
TextBox3.Focus()
End If
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
TextBox3.MaxLength = 50
If e.KeyChar = Chr(13) Then
TextBox4.Focus()
End If
End Sub
Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
TextBox4.MaxLength = 50
If e.KeyChar = Chr(13) Then
TextBox5.Focus()
End If
End Sub
Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
TextBox5.MaxLength = 50
If e.KeyChar = Chr(13) Then
Button1.Focus()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
MsgBox("data belum lengkap")
Exit Sub
Else
Call Koneksi()
CMD = New SqlCommand("select * from TBLCUSTOMER where KODE_CUSTOMER='" & TextBox1.Text & "'", CONN)
DR = CMD.ExecuteReader
DR.Read()
If Not DR.HasRows Then
Call Koneksi()
Dim simpan As String = "Insert into TBLCUSTOMER values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')"
CMD = New SqlCommand(simpan, CONN)
CMD.ExecuteNonQuery()
Else
Call Koneksi()
Dim edit As String = "update TBLCUSTOMER set NAMA_CUSTOMER='" & TextBox2.Text & "',ALAMAT_CUSTOMER='" & TextBox3.Text & "',TELPON_CUSTOMER='" & TextBox4.Text & "',CONTACT_PERSON='" & TextBox5.Text & "' where KODE_CUSTOMER='" & TextBox1.Text & "'"
CMD = New SqlCommand(edit, CONN)
CMD.ExecuteNonQuery()
End If
Call Kosongkan()
Call TampilGrid()
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MsgBox("KODE CUSTOMER harus diisi dulu")
TextBox1.Focus()
Exit Sub
Else
If MessageBox.Show("hapus data ini....?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Call Koneksi()
Dim hapus As String = "delete from TBLCUSTOMER where KODE_CUSTOMER='" & TextBox1.Text & "'"
CMD = New SqlCommand(hapus, CONN)
CMD.ExecuteNonQuery()
Call Kosongkan()
Call TampilGrid()
Else
Call Kosongkan()
End If
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call Kosongkan()
End Sub
Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
Call Koneksi()
CMD = New SqlCommand(" select * from TBLCUSTOMER where NAMA_CUSTOMER like '%" & TextBox6.Text & "%'", CONN)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows Then
Call Koneksi()
DA = New SqlDataAdapter(" select * from TBLCUSTOMER where NAMA_CUSTOMER like '%" & TextBox6.Text & "%'", CONN)
DS = New DataSet
DA.Fill(DS)
DGV.DataSource = DS.Tables(0)
Else
MsgBox("nama tidak di temukan")
End If
End Sub
Private Sub DGV_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick
On Error Resume Next
TextBox1.Text = DGV.Rows(e.RowIndex).Cells(0).Value
TextBox2.Text = DGV.Rows(e.RowIndex).Cells(1).Value
TextBox3.Text = DGV.Rows(e.RowIndex).Cells(2).Value
TextBox4.Text = DGV.Rows(e.RowIndex).Cells(3).Value
TextBox5.Text = DGV.Rows(e.RowIndex).Cells(4).Value
End Sub
End Class

====================================
source code
====================================
Imports System.Data.SqlClient
Public Class CUSTOMER
Sub Kosongkan()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox1.Focus()
End Sub
Sub DataBaru()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox2.Focus()
End Sub
Sub TampilGrid()
Call Koneksi()
DA = New SqlDataAdapter("select * from TBLCUSTOMER", CONN)
DS = New DataSet
DA.Fill(DS)
DGV.DataSource = DS.Tables(0)
DGV.ReadOnly = True
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Koneksi()
Call TampilGrid()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
TextBox1.MaxLength = 10
If e.KeyChar = Chr(13) Then
Call Koneksi()
CMD = New SqlCommand("select * from TBLCUSTOMER where KODE_CUSTOMER='" & TextBox1.Text & "'", CONN)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows Then
TextBox2.Text = DR.Item("NAMA_CUSTOMER")
TextBox3.Text = DR.Item("ALAMAT_CUSTOMER")
TextBox4.Text = DR.Item("TELPON_CUSTOMER")
TextBox5.Text = DR.Item("CONTACT_PERSON")
TextBox2.Focus()
Else
Call DataBaru()
End If
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
TextBox2.MaxLength = 50
If e.KeyChar = Chr(13) Then
TextBox3.Focus()
End If
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
TextBox3.MaxLength = 50
If e.KeyChar = Chr(13) Then
TextBox4.Focus()
End If
End Sub
Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
TextBox4.MaxLength = 50
If e.KeyChar = Chr(13) Then
TextBox5.Focus()
End If
End Sub
Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
TextBox5.MaxLength = 50
If e.KeyChar = Chr(13) Then
Button1.Focus()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Then
MsgBox("data belum lengkap")
Exit Sub
Else
Call Koneksi()
CMD = New SqlCommand("select * from TBLCUSTOMER where KODE_CUSTOMER='" & TextBox1.Text & "'", CONN)
DR = CMD.ExecuteReader
DR.Read()
If Not DR.HasRows Then
Call Koneksi()
Dim simpan As String = "Insert into TBLCUSTOMER values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')"
CMD = New SqlCommand(simpan, CONN)
CMD.ExecuteNonQuery()
Else
Call Koneksi()
Dim edit As String = "update TBLCUSTOMER set NAMA_CUSTOMER='" & TextBox2.Text & "',ALAMAT_CUSTOMER='" & TextBox3.Text & "',TELPON_CUSTOMER='" & TextBox4.Text & "',CONTACT_PERSON='" & TextBox5.Text & "' where KODE_CUSTOMER='" & TextBox1.Text & "'"
CMD = New SqlCommand(edit, CONN)
CMD.ExecuteNonQuery()
End If
Call Kosongkan()
Call TampilGrid()
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MsgBox("KODE CUSTOMER harus diisi dulu")
TextBox1.Focus()
Exit Sub
Else
If MessageBox.Show("hapus data ini....?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Call Koneksi()
Dim hapus As String = "delete from TBLCUSTOMER where KODE_CUSTOMER='" & TextBox1.Text & "'"
CMD = New SqlCommand(hapus, CONN)
CMD.ExecuteNonQuery()
Call Kosongkan()
Call TampilGrid()
Else
Call Kosongkan()
End If
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call Kosongkan()
End Sub
Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
Call Koneksi()
CMD = New SqlCommand(" select * from TBLCUSTOMER where NAMA_CUSTOMER like '%" & TextBox6.Text & "%'", CONN)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows Then
Call Koneksi()
DA = New SqlDataAdapter(" select * from TBLCUSTOMER where NAMA_CUSTOMER like '%" & TextBox6.Text & "%'", CONN)
DS = New DataSet
DA.Fill(DS)
DGV.DataSource = DS.Tables(0)
Else
MsgBox("nama tidak di temukan")
End If
End Sub
Private Sub DGV_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick
On Error Resume Next
TextBox1.Text = DGV.Rows(e.RowIndex).Cells(0).Value
TextBox2.Text = DGV.Rows(e.RowIndex).Cells(1).Value
TextBox3.Text = DGV.Rows(e.RowIndex).Cells(2).Value
TextBox4.Text = DGV.Rows(e.RowIndex).Cells(3).Value
TextBox5.Text = DGV.Rows(e.RowIndex).Cells(4).Value
End Sub
End Class

0
1.2K
2


Komentar yang asik ya
Urutan
Terbaru
Terlama


Komentar yang asik ya
Komunitas Pilihan