Senin, 07 Mei 2012

Memanggil Stored Procedure dari VB.NET

Berikut ini cara memanggil Stored Procedure dengan Parameter Masukan dan Keluaran di VB.NET

Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim lreturn As Boolean = True
con.ConnectionString = Settings.ConnectionString
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "totalgaji"
 
cmd.Parameters.Add("@kode", SqlDbType.Varchar)

cmd.Parameters("@kode").Direction = ParameterDirection.Input
  cmd.Parameters("@kode").Value = 'MKT' cmd.Parameters.Add("@hasil", SqlDbType.Int)
cmd.Parameters("@hasil").Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()
Dim intCount As Integer = 0
Integer.TryParse(cmd.Parameters("@hasil").Value, intCount)
If intCount > 0 Then MessageBox.Show("Total Gaji " & intCount.ToString() & "")
con.Close()