ShoutMix chat widget

Rabu, 08 Juni 2011

Entry Data

Cari Data
sub jurusan()
call koneksi
tampil2.connection = database
tampil2.CommandType = Commandtype.Text
tampil2.CommandText = "select * from jurusan where kdjur='" &Trim(TextBox1.Text)& "'
tampilkan = tampil2.Executereader

if tampilkan.Hasrows = True than
while tampilkan.read()
if ISDBNull (Tampilkan("kdjur")) Then
TextBox2.text="_"
else
TextBox2.Text = Tampilkan("nmjur")
End if
End While
End if

CEK RECORD

Sub cekrecord()
call koneksi()
tampil.connection = database
tampil.commandType=commandtype.Text
tampil.commandText = "Select * from jurusan where kd='" & trim(Textbox1.text)& "'
tampilkan = tampil.executeReader

if tampilkan.Hasrows = true then
hasilcek = true
else
hasilcek = false
end if
end sub

INSERT DATA

if TextBox1.Text = "" Then exit sub
if TextBox2.Text = "" Then Exit Sub
call koneksi()

Try
if hasilcek = "false" then
call koneksi()

tampil.connection = database
tampil.commandType = CommandText.Text
tampil.commandType = " insert into jurusan (kdjur,nmjur)values('" & TextBox1.text & "','" & TextBox.text & "')"
tampil.ExecuteNonQuery()
call kosong()
else
msgBox("data sudah ada", msgboxStyle.Critical,"input data")
textbox1.focus()
end if
Catch ex As exception
msgBox(ex.ToString())
end if
end sub


UBAH DATA/ UPDATE/b>

Try
call koneksi()
tampil.connection= database
tampil.commandType = commandType.Text
tampil.commandText = " update jurusan set nmjur='"& Trim(TextBox2.Text) & "' where
kdjur = '" & Trim(TextBox1.Text) & "'"
tampil.ExecuteNonQuery()
call kosong()
TextBox1.Focus()
catch ex As Exception
msgBox(ex.ToString())
end try
end sub

Kamis, 19 Mei 2011

Koneksi VB 2010 Database SQL sever

Untuk menghubungkan VB ke SQL Server diperlukan variabel

Public Database As New OleDb.OleDbConnection
Public Tampil As New OleDb.OleDbCommand
Public Tampil2 As New OleDb.OleDbCommand
Public Tampilkan As OleDb.OleDbDataReader




Untuk konek database sever:

Database.connectionstring = "Provider = SQLOLEDB.1; Password=sandi; persist security
Info = True; User ID = SS; Initial Catalog = nmdatabase; Data Source = 192.168.10.44" ( Data source bisa nama komputer sever atau no IP nya)

Untuk koneksi ke database lokal:

Database.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info= False; Initial Catalog = jurusan; Data Source = BATURADE-D8AD88\SQLEXPRESS;"

Contoh:

Buat dulu class module
Module konek
Public Database As New OleDb.OleDbConnection
Public Tampil As New OleDb.OleDbCommand
Public Tampil2 As New OleDb.OleDbCommand
Public Tampilkan As OleDb.OleDbDataReader
Public nmjur, kdjur, hasilcek As String
Public Sub koneksi()
Try
Database.Close()
Database.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info= False; Initial Catalog = jurusan; Data Source = BATURADE-D8AD88\SQLEXPRESS;"
Database.Open()
MsgBox("koneksi berhasil")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

End Module

Coding di form:

Public Class Form1
Sub jurusan()
Call koneksi()
Tampil2.Connection = Database
Tampil2.CommandType = CommandType.Text
Tampil2.CommandText = " select * from jurusan where kdjur ='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil2.ExecuteReader

If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(Tampilkan("kdjur")) Then
TextBox2.Text = "_"
Else
TextBox2.Text = Tampilkan("nmjur")
End If
End While
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call koneksi()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call jurusan()
End Sub
End Class

Hasilnya :

Selasa, 19 April 2011

Looping


Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim j, u, y As Integer
u = 4
y = 7
For j = 1 To Val(TextBox1.Text)
If j Mod u = 0 Then
ListBox1.Items.Add(j)
u = j
Else
If j Mod y = 0 Then
ListBox1.Items.Add(j)
y = j
End If
End If
Next
End Sub
End Class

Kamis, 31 Maret 2011

input ke listview

Public Class Form1
Dim isitext(4) As String 'var Array
Dim mylisitem As ListViewItem
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call bersih()
Call isi_combo()
Call Set_Tampilan()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
ComboBox1.Text = "06 Teknik Informatika"
End Sub
Sub isi_combo()
ComboBox1.Items.Add("06 Teknik Informatika")
ComboBox1.Items.Add("07 Sistem Informasi")
ComboBox1.Items.Add("67. Komputer Akuntansi")
ComboBox1.Items.Add("05 Teknik Komputer")
ComboBox1.Items.Add("26 Manajemen Informatika")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Tambah" Then
Button1.Text = "Simpan"
Button2.Enabled = False 'INI
Button3.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
'membuat array
isitext(0) = Trim(TextBox1.Text)
isitext(1) = Trim(TextBox2.Text)
isitext(2) = Trim(TextBox3.Text) 'UNTUK MENAMPILKAN SEMUA
isitext(3) = Microsoft.VisualBasic.Left(Trim(ComboBox1.Text), 2) 'mengambil 2 digit dari kiri dari kombobox
mylisitem = New ListViewItem(isitext) 'dipindahkan secara permanen
ListView1.Items.Add(mylisitem)
Call bersih()
TextBox1.Focus()
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "keluar" Then
Me.Close() 'FUNGSI UNTUK KELUAR DALAM FORM SENDIRI
Else
Call bersih()
Call normal()
End If
End Sub
Sub normal()
Button1.Text = "Tambah"
Button1.Enabled = True 'INI
Button2.Text = "Ubah"
Button2.Enabled = True 'INI
Button3.Text = "Hapus"
Button3.Enabled = True 'INI
Button4.Text = "keluar"
Button4.Enabled = True 'INI
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Text = "Ubah" Then
Button2.Text = "Simpan"
Button1.Enabled = False 'INi
Button3.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button3.Text = "Hapus" Then
Button3.Text = "Simpan"
Button1.Enabled = False 'INI
Button2.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
End If
End Sub
Sub Set_Tampilan()
ListView1.View = View.Details 'membentuk tampilan menjadi macam2
'membuat kolom : ( nama kolom, lebar kolom, posisi tulisan)
ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Nama", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Alamat", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Jurusan", 100, HorizontalAlignment.Center)
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
TextBox1.Text = e.Item.Text 'INI --> e
End Sub
End Class

Input Data




List Programnya
Public Class Form1
Sub BERSIH()
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox3.Focus()
End Sub
Sub perintah()
Dim s As Integer
s = 6
If TextBox1.Text = "TI" Then
TextBox2.Text = "Teknik Informatika"
Else
If TextBox1.Text = "SI" Then
TextBox2.Text = "Sistem Informatika"
End If

End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call perintah()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListBox1.Items.Add(Trim(TextBox3.Text) + " " + Trim(TextBox4.Text) + " " + Trim(TextBox5.Text))
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call BERSIH()
End Sub
End Class

pengulangan

Operasi Perulangan
Operasi Perulangan dengan for....
contoh 1 . menampilkan bilangan genap
cuplikan program

Public Class Form1

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
ListBox1.Items.Clear()
For i = 1 To Val(TextBox1.Text)
If i Mod 2 = 0 Then
ListBox1.Items.Add(i)
End If
Next
End Sub
End Class



contoh 2 Menampilkan bilangan 4,7,8,14,16,28,32,56...

Listing programnya:

Public Class Form2

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, u, y As Integer
u = 4
y = 7
For i = 1 To Val(TextBox1.Text)
If i Mod u = 0 Then
ListBox1.Items.Add(i)
u = i
Else
If i Mod y = 0 Then
ListBox1.Items.Add(i)
y = i


End If
End If
Next
End Sub
End Class

Rabu, 30 Maret 2011

Mod



Mod 4 sisa 3
List Programnya

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
ListBox1.Items.Clear()
For i = 1 To Val(TextBox1.Text)
If (i Mod 4 = 3) Then
ListBox1.Items.Add(i)
End If
Next
End Sub
End Class

Bilangan yang jabis di bagi 7 dan 4
list Programnya



Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
ListBox1.Items.Clear()
For i = 1 To Val(TextBox1.Text)
If (i Mod 7 = 0) And (i Mod 4 = 0) Then
ListBox1.Items.Add(i)
End If
Next
End Sub
End Class