VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Handle Input / Output Parameters With .Net

by Gehan Fernando (47 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Thu 13th September 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Handle Input / Output Parameters With .Net

API Declarations


.SqlClient

'SQL Procedure
'CREATE PROC GetCustomID (@PassValue NVARCHAR(100),@Type CHAR(1),@GetID INT OUTPUT)
'AS
' IF @Type = 'D'
' BEGIN
' SELECT @GetID = MAX(ISNULL(EmployeeID,0)) + 1 FROM
' Employees
' END
' ELSE
' BEGIN
' SELECT @GetID = MAX(ISNULL(EmployeeID,0)) + 1 FROM
' Employees
' WHERE FirstName LIKE @PassValue + '%'
' END
'GO

Rate Handle Input / Output Parameters With .Net




    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

Download this snippet    Add to My Saved Code

Handle Input / Output Parameters With .Net Comments

No comments have been posted about Handle Input / Output Parameters With .Net. Why not be the first to post a comment about Handle Input / Output Parameters With .Net.

Post your comment

Subject:
Message:
0/1000 characters