VB Tugas Script
VB Tugas Script
Configuration
Imports System.Data.SqlClient
Public Class Form1
Private koneksi As String =
System.Configuration.ConfigurationManager.ConnectionStrings("conn").ConnectionString()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
tampil()
End Sub
End Sub
End Sub
Private Sub dgv_Click(sender As Object, e As EventArgs) Handles dgv.Click
txtid.Text = dgv.SelectedRows(0).Cells("ID").Value
txtkota.Text = dgv.SelectedRows(0).Cells("Nama Kota").Value
txtprov.Text = dgv.SelectedRows(0).Cells("Provinsi").Value
btnsave.Text = "Update"
End Sub
Private Sub segarkan()
txtid.Text = String.Empty
txtkota.Text = String.Empty
txtprov.Text = String.Empty
btnsave.Text = "Save"
End Sub
'addnewcommand.Parameters.AddWithValue("add1", txtid.Text)
newconnection.Open()
addnewcommand.ExecuteNonQuery()
newconnection.Close()
MsgBox("Data di hapus", vbExclamation, "DATA NEGARA")
tampil()
segarkan()
txtkota.Focus()
End If
End Sub
'addnewcommand.Parameters.AddWithValue("add1", txtkota.Text)
'addnewcommand.Parameters.AddWithValue("add2", txtprov.Text)
'addnewcommand.Parameters.AddWithValue("add3", txtid.Text)
newconnection.Open()
addnewcommand.ExecuteNonQuery()
newconnection.Close()
MsgBox("Data sudah di update", vbExclamation, "DATA NEGARA")
tampil()
btnsave.Text = "Save"
segarkan()
txtkota.Focus()
Else
Dim newconnection As New OleDb.OleDbConnection(koneksi)
Dim queryresult As Integer
Dim addstr As String = "SELECT COUNT (namakota) FROM tbprovinsi WHERE
namakota = '" & txtkota.Text & "'"
Dim addnewcommand As New OleDb.OleDbCommand
addnewcommand.Connection = newconnection
addnewcommand.CommandText = addstr
newconnection.Open()
queryresult = addnewcommand.ExecuteScalar()
newconnection.Close()
If queryresult > 0 Then
MsgBox("Nama Kota Sudah Ada", vbExclamation, "ERROR")
Else
Dim newconnection1 As New OleDb.OleDbConnection(koneksi)
Dim addstr1 As String = "INSERT INTO tbprovinsi (namakota,provinsi)
VALUES ('" & txtkota.Text & "','" & txtprov.Text & "')"
Dim addnewcommand1 As New OleDb.OleDbCommand
addnewcommand1.Connection = newconnection1
addnewcommand1.CommandText = addstr1
'addnewcommand.Parameters.AddWithValue("add1", txtkota.Text)
'addnewcommand.Parameters.AddWithValue("add2", txtprov.Text)
newconnection1.Open()
addnewcommand1.ExecuteNonQuery()
newconnection1.Close()