Personal Mind of ASEP

Sepercik Rasa yang Tercurah

Nambah Record Ke MySql di vb.Net

Dim InsertQuery As String
Dim Kelamin As String
Dim hasil As Integer
Dim cmd As MySqlCommand

If rbPria.Checked = True Then
Kelamin = rbPria.Text
Else
Kelamin = rbWanita.Text
End If

InsertQuery = “INSERT INTO Anggota ” & _
“(id_anggota, nama, alamat, jenis_kelamin)” & _
” Values(‘” & txtId.Text & “‘, ” & _
” ‘” & txtNama.Text & “‘, ” & _
” ‘” & txtAlamat.Text & “‘, ‘” & Kelamin & “‘)”

Try
cmd = New MySqlCommand(InsertQuery, Conn)
cmd.Connection.Open()
‘ eksekusi pernyataan SQL
hasil = cmd.ExecuteNonQuery()
‘ periksa nilai yang dikembalikan
If (hasil > 0) Then
MessageBox.Show(“Record Berhasil Dimasukkan”, _
“Sukses”, MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Clear()
End If
Catch ex As MySqlException
MessageBox.Show(“Failed : ” & ex.Message, “Gagal”, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
cmd.Connection.Close()
cmd.Dispose()

September 26, 2005 - Posted by | Uncategorized

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: