Author : Gehan Fernando
Date Submitted : 9/13/2007
Category : Database
Compatibility : .NET
This code has been accessed 4403 times.
Task : Handle Input / Output Parameters With .Net
Declarations
Code
Public Class Form1
Private con As SqlConnection
Private com As SqlCommand
Private Type As Char = "D"c
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
con = New SqlConnection("Data Source=RAS7;Initial Catalog=Northwind;Integrated Security=True;Min Pool Size=5;Max Pool Size=20;Connect Timeout=30;Network Library=dbnmpntw")
con.Open()
com = New SqlCommand()
With com
.Connection = con
.CommandType = CommandType.StoredProcedure
.CommandText = "GetCustomID"
.Parameters.Add("@PassValue", SqlDbType.NVarChar, 100).Value = TextBox1.Text.ToString().Trim()
.Parameters.Add("@Type", SqlDbType.Char, 1).Value = Type.ToString().Trim()
.Parameters.Add("@GetID", SqlDbType.Int).Direction = ParameterDirection.Output
.ExecuteScalar()
TextBox2.Text = .Parameters.Item("@GetID").Value.ToString()
End With
com.Parameters.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
com.Dispose()
con.Dispose()
End Try
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then Type = "D"c
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then Type = "N"c
End Sub
End Class