Dim con As SqlConnection
Dim cmd As SqlCommand
Dim MyAdapter As SqlDataAdapter
Dim MyReader As DataSet
Dim style As MsgBoxStyle
Dim respons As MsgBoxResult
Dim paramNik, paramNama, paramAlamat, paramKota As SqlParameter
Dim sTr, Pesan, msg As String
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Menggunakan stored procedure di sql server 2000
Try
con = New SqlConnection("server=(local);user id=sa;password=;database=hrd")
con.Open()
cmd = New SqlCommand("spInsMstKaryawan", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@nik", SqlDbType.NVarChar, 10))
cmd.Parameters.Add(New SqlParameter("@nama", SqlDbType.NVarChar, 25))
cmd.Parameters.Add(New SqlParameter("@alamat", SqlDbType.NVarChar, 30))
cmd.Parameters.Add(New SqlParameter("@kota", SqlDbType.NVarChar, 20))
cmd.Parameters("@nik").Value = TextBox1.Text
cmd.Parameters("@nama").Value = TextBox2.Text
cmd.Parameters("@alamat").Value = TextBox3.Text
cmd.Parameters("@kota").Value = DropDownList1.Text
msg = "Apakah Yakin Data Ini Di Simpan?" ' Define message.
style = MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
Title = "MsgBox Simpan" ' Define title.
' Menampilkan Pesan
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("Data Tdk Boleh Kosong", MsgBoxStyle.Information, "Simpan")
Else
respons = MsgBox(msg, style, Title)
If respons = MsgBoxResult.Yes Then ' User chose Yes.
' Perform some action.
cmd.ExecuteNonQuery()
MsgBox("Data Tersimpan", MsgBoxStyle.Information, "Simpan")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End If
End If
Catch msg1 As SqlException
MsgBox(msg1, MsgBoxStyle.Critical, "Error")
End Try
con.Close()
End Sub