Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi ...

I have Table Called "ItemsPricesTbl"

Contain :

ItemID
FirstUnitWholeSalePrice
FirstUnitShopperPrice
FirstUnitDemotionsPrice
FirstUnitPriceDefult
SecondUnitWholeSalePrice
SecondUnitShopperPrice
SecondUnitDemotionsPrice
SecondUnitPriceDefult
ThirdUnitWholeSalePrice
ThirdUnitShopperPrice
ThirdUnitDemotionsPrice
ThirdUnitPriceDefult
DefultPrice



The Stored Porc is :

SQL
ALTER PROCEDURE [dbo].[Get_Prices_Item_By_ID]

@ItemID int

as

begin

Select ItemID,FirstUnitWholeSalePrice,FirstUnitShopperPrice,FirstUnitDemotionsPrice,FirstUnitPriceDefult,SecondUnitWholeSalePrice,SecondUnitShopperPrice,SecondUnitDemotionsPrice,SecondUnitPriceDefult,ThirdUnitWholeSalePrice,ThirdUnitShopperPrice,ThirdUnitDemotionsPrice,ThirdUnitPriceDefult,DefultPrice from ItemsPricesTbl Where ItemID=@ItemID

End


in Vb i have DatabaseManager Class Which Have this Code :


VB
Private Function exeReader(ByRef cmd As SqlCommand, ByRef dr As SqlDataReader) As Integer
        Dim retval As Integer = -1
        cmd.Connection = Me.Connection
        Try
            If cmd.CommandType = CommandType.StoredProcedure Then
                Dim pr As New SqlParameter("@retval", SqlDbType.Int)
                pr.Direction = ParameterDirection.ReturnValue
                cmd.Parameters.Add(pr)
            End If
            If cmd.Connection.State = ConnectionState.Closed Then cmd.Connection.Open()
            dr = cmd.ExecuteReader()

            If cmd.CommandType = CommandType.StoredProcedure Then retval = cmd.Parameters("@retval").Value
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Me.close()
        End Try

        Return retval
    End Function




Also I have two classes The Data Class And Business Class .

Data Class Code :

VB
Friend Function Get_Prices_Item_By_ID(ByRef cmd As SqlCommand, ByRef dr As SqlDataReader, ByVal ItemID As Integer) As Integer
            Dim retval As String
            cmd = New SqlCommand("Get_Prices_Item_By_ID")
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitWholeSalePrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitShopperPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitDemotionsPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitPriceDefult", SqlDbType.Bit)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitWholeSalePrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitShopperPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitDemotionsPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitPriceDefult", SqlDbType.Bit)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitWholeSalePrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitShopperPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitDemotionsPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitPriceDefult", SqlDbType.Bit)
            daa.SelectCommand.Parameters.AddWithValue("@DefultPrice", SqlDbType.Int)
            dr = cmd.ExecuteReader()
            Return retval
        End Function



And Business Class Code :

VB
Public Function Get_Prices_Item_By_ID(ByVal ItemID As Integer) As DataTable
    Dim dt As New DataTable
    p.Get_Prices_Item_By_ID(dt)
    Return dt
End Function



What Code I have to Put in search Button ?
How To Display Record From SQL To TextBox 


What I have tried:

The Stored Porc is : 

<pre lang="SQL">ALTER PROCEDURE [dbo].[Get_Prices_Item_By_ID]

@ItemID int

as

begin

Select ItemID,FirstUnitWholeSalePrice,FirstUnitShopperPrice,FirstUnitDemotionsPrice,FirstUnitPriceDefult,SecondUnitWholeSalePrice,SecondUnitShopperPrice,SecondUnitDemotionsPrice,SecondUnitPriceDefult,ThirdUnitWholeSalePrice,ThirdUnitShopperPrice,ThirdUnitDemotionsPrice,ThirdUnitPriceDefult,DefultPrice from ItemsPricesTbl Where ItemID=@ItemID

End


in Vb i have DatabaseManager Class Which Have this Code :


VB
Private Function exeReader(ByRef cmd As SqlCommand, ByRef dr As SqlDataReader) As Integer
        Dim retval As Integer = -1
        cmd.Connection = Me.Connection
        Try
            If cmd.CommandType = CommandType.StoredProcedure Then
                Dim pr As New SqlParameter("@retval", SqlDbType.Int)
                pr.Direction = ParameterDirection.ReturnValue
                cmd.Parameters.Add(pr)
            End If
            If cmd.Connection.State = ConnectionState.Closed Then cmd.Connection.Open()
            dr = cmd.ExecuteReader()

            If cmd.CommandType = CommandType.StoredProcedure Then retval = cmd.Parameters("@retval").Value
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Me.close()
        End Try

        Return retval
    End Function




Also I have two classes The Data Class And Business Class .

Data Class Code :

VB
Friend Function Get_Prices_Item_By_ID(ByRef cmd As SqlCommand, ByRef dr As SqlDataReader, ByVal ItemID As Integer) As Integer
            Dim retval As String
            cmd = New SqlCommand("Get_Prices_Item_By_ID")
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitWholeSalePrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitShopperPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitDemotionsPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitPriceDefult", SqlDbType.Bit)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitWholeSalePrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitShopperPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitDemotionsPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitPriceDefult", SqlDbType.Bit)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitWholeSalePrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitShopperPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitDemotionsPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitPriceDefult", SqlDbType.Bit)
            daa.SelectCommand.Parameters.AddWithValue("@DefultPrice", SqlDbType.Int)
            dr = cmd.ExecuteReader()
            Return retval
        End Function



And Business Class Code :

VB
Public Function Get_Prices_Item_By_ID(ByVal ItemID As Integer) As DataTable
    Dim dt As New DataTable
    p.Get_Prices_Item_By_ID(dt)
    Return dt
End Function
Posted
Updated 22-Apr-17 4:00am
Comments
Richard MacCutchan 22-Apr-17 9:24am    
Why have you posted all this code twice: Once is more than enough? Also your problem description is far from clear. Displaying data in a textbox is just a matter of capturing the data, formatting it to your specification, and setting it into the textbox's Text property.

1 solution

Pretty much all you have to do is add a second parameter to your existing SqlReader code:
VB
Dim pr As New SqlParameter("@retval", SqlDbType.Int)
pr.Direction = ParameterDirection.ReturnValue
cmd.Parameters.Add(pr)
cmd.Parameters.AddWithValue("@ItemID", idOfTheItemYouWantToSearchFor)
Your reader can then fetch the values and add them to your textbox.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900