How to fill listbox with multiple selected value from SQL database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • polluxsoftech
    New Member
    • Jun 2010
    • 2

    How to fill listbox with multiple selected value from SQL database

    HI,
    I have 1 listbox named lbCountry
    i have inserted each selected value from listbox into database by following code:
    Code:
    For iLoop = 0 To lbCountry.Items.Count - 1
        ' item selected
        Dim i As Integer() = New Integer(iLoop) {}
        If lbCountry.Items(iLoop).Selected Then
            i(iLoop) = CInt(lbCountry.Items(iLoop).Value.ToString())
            objPartnerDetailsInfo.BIntPreferenceId = i(iLoop)
    
            objPartnerDetailsInfo.VarPreference = lbCountry.ID
            objPartnerDetailsInfo.BIntProfileId = Session("ProfileId")
            objPartnerDetails.Insert(objPartnerDetailsInfo)
        End If
    Next


    in class :
    Code:
    Public Sub Insert(ByVal objPartnerDetailsInfo As PartnerDetailsInfo)
            conn = New SqlConnection(constr)
            conn.Open()
            cmd = New SqlCommand("SPAddEditPartnerDetails", conn)
            cmd.Parameters.Add("@Operation", "Add")
            cmd.Parameters.Add("@BIntPartnerDetailsId", SqlDbType.BigInt).Value = DBNull.Value
            cmd.Parameters.Add("@BIntPreferenceId", SqlDbType.BigInt).Value = objPartnerDetailsInfo.BIntPreferenceId
            cmd.Parameters.Add("@VarPreference", SqlDbType.VarChar).Value = objPartnerDetailsInfo.VarPreference
            cmd.Parameters.Add("@BIntProfileId", SqlDbType.BigInt).Value = objPartnerDetailsInfo.BIntProfileId
            cmd.CommandType = CommandType.StoredProcedure
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            conn.Close()
        End Sub
    'following is my stored procedure
    Code:
    ALTER PROCEDURE [dbo].[SPAddEditPartnerDetails]
    	
    	@operation varchar(50),
    	@BIntPartnerDetailsId BIGINT,
    	@BIntProfileId BIGINT,
    	@BIntPreferenceId bigint,
    	@VarPreference varchar(50)
    AS
    If @operation ='Add'
    BEGIN
    	Insert tblPartnerDetails
    		(
    	BIntProfileId,
    	BIntPreferenceId,
    	VarPreference
    		)
    	VALUES
    		(
    	@BIntProfileId,
    	@BIntPreferenceId,
    	@VarPreference
    		)
    	Select @BIntPartnerDetailsId=@@Identity
    
    	END
    now i dont know how to fetch data from databse and fill listbox with multiple selected value..
    plz give suitable solution..
    Last edited by Frinavale; Jun 30 '10, 04:01 PM. Reason: Please post code in [code] ... [/code] tags. Fixed code tags.
  • Toniyo Jackson
    New Member
    • Jun 2010
    • 4

    #2
    try this

    Code:
    For intItem As Integer = 0 To lstBox.Items.Count - 1
      For intSel As Integer = 0 To objDT.Rows.Count - 1
        If lstBox.Items(intItem).Value = CInt(objDT.Rows(intSel).Item("Screen_Id")) Then
          lstBox.Items(intItem).Selected = True
        End If
      Next
    Next
    Last edited by Frinavale; Jun 30 '10, 04:02 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

    Comment

    Working...