Salam damai sejahtera bagi kita semua, disini saya akan membagi totorial tentang bagaiman cara memanggil stored procedure ke VB. Net. mungkin ada yang sudah mahir dalam hal ini, tapi tidak ada salahnya saya akan membagi ini buat teman-teman yang baru belajar seperti saya.
oke langsung saja
.........................................................................................................................................................
disini saya buat contoh stored procedurnya dengan nama SP_simpansiswa
.........................................................................................................................................................
CREATE PROCEDURE simpansiswa
@nis varchar (5), @nama varchar (10)
AS
BEGIN
insert into tblsiswa values(@nis,@nama)
END
GO
-----------------------------------------------------------------------------------------------------------------
sekarang kita masuk ke VB.net 2008
pertama-tama kita buat classs
-----------------------------------------------------------------------------------------------------------------
import system.data.sqlclient ' digunakan supaya perintah sqlcommand , sqldatareader dll , dapat dikenali di VB.net nya
.....................................................................................................................................................
public class clssiswa
public fnis as string 'nama parameter di VB.net
public fnm as string
------------------------------------------------------------------------------------------------------------------
Public Property Pnis() As String
Get
Return fnis
End Get
Set(ByVal value As String)
fnis = value
End Set
End Property
Public Property Pnm() As String
Get
Return fnm
End Get
Set(ByVal value As String)
fnm = value
End Set
End Property
--------------------------------------------------------------------------------------------------------------------------
Public Function simpan()
Dim i As Integer
Dim xcmd As SqlCommand
xcmd = New SqlCommand("sp_simpansiswa", con) 'cara memanggil storeprocedur di vb.net
xcmd.CommandType = CommandType.StoredProcedure
With xcmd.Parameters
.AddWithValue("@nis", fnis)
.AddWithValue("@nama", fnm)
End With
i = xcmd.ExecuteNonQuery
Return i
End Function
end class
--------------------------------------------------------------------------------------------------------------------------
klik 2kali pada command simpan
-------------------------------------------------------------------------------------------------------------------------
Dim nilai As Integer
With x
.Pnis = txtnis.Text
.Pnm = txtnm.Text
.Palamat = txtalmt.Text
End With
nilai = x.simpan
If nilai = 1 Then
MsgBox("data berhasil disimpan!", MsgBoxStyle.Information)
End If
selamat mencoba teman-teman semoga sukses .....
oke langsung saja
.........................................................................................................................................................
disini saya buat contoh stored procedurnya dengan nama SP_simpansiswa
.........................................................................................................................................................
CREATE PROCEDURE simpansiswa
@nis varchar (5), @nama varchar (10)
AS
BEGIN
insert into tblsiswa values(@nis,@nama)
END
GO
-----------------------------------------------------------------------------------------------------------------
sekarang kita masuk ke VB.net 2008
pertama-tama kita buat classs
-----------------------------------------------------------------------------------------------------------------
import system.data.sqlclient ' digunakan supaya perintah sqlcommand , sqldatareader dll , dapat dikenali di VB.net nya
.....................................................................................................................................................
public class clssiswa
public fnis as string 'nama parameter di VB.net
public fnm as string
------------------------------------------------------------------------------------------------------------------
Public Property Pnis() As String
Get
Return fnis
End Get
Set(ByVal value As String)
fnis = value
End Set
End Property
Public Property Pnm() As String
Get
Return fnm
End Get
Set(ByVal value As String)
fnm = value
End Set
End Property
--------------------------------------------------------------------------------------------------------------------------
Public Function simpan()
Dim i As Integer
Dim xcmd As SqlCommand
xcmd = New SqlCommand("sp_simpansiswa", con) 'cara memanggil storeprocedur di vb.net
xcmd.CommandType = CommandType.StoredProcedure
With xcmd.Parameters
.AddWithValue("@nis", fnis)
.AddWithValue("@nama", fnm)
End With
i = xcmd.ExecuteNonQuery
Return i
End Function
end class
--------------------------------------------------------------------------------------------------------------------------
klik 2kali pada command simpan
-------------------------------------------------------------------------------------------------------------------------
Dim nilai As Integer
With x
.Pnis = txtnis.Text
.Pnm = txtnm.Text
.Palamat = txtalmt.Text
End With
nilai = x.simpan
If nilai = 1 Then
MsgBox("data berhasil disimpan!", MsgBoxStyle.Information)
End If
selamat mencoba teman-teman semoga sukses .....
Thank You Bro, Tutorialnya sangat membantu.
ReplyDelete