473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. For iLoop = 0 To lbCountry.Items.Count - 1
  2.     ' item selected
  3.     Dim i As Integer() = New Integer(iLoop) {}
  4.     If lbCountry.Items(iLoop).Selected Then
  5.         i(iLoop) = CInt(lbCountry.Items(iLoop).Value.ToString())
  6.         objPartnerDetailsInfo.BIntPreferenceId = i(iLoop)
  7.  
  8.         objPartnerDetailsInfo.VarPreference = lbCountry.ID
  9.         objPartnerDetailsInfo.BIntProfileId = Session("ProfileId")
  10.         objPartnerDetails.Insert(objPartnerDetailsInfo)
  11.     End If
  12. Next


in class :
Expand|Select|Wrap|Line Numbers
  1. Public Sub Insert(ByVal objPartnerDetailsInfo As PartnerDetailsInfo)
  2.         conn = New SqlConnection(constr)
  3.         conn.Open()
  4.         cmd = New SqlCommand("SPAddEditPartnerDetails", conn)
  5.         cmd.Parameters.Add("@Operation", "Add")
  6.         cmd.Parameters.Add("@BIntPartnerDetailsId", SqlDbType.BigInt).Value = DBNull.Value
  7.         cmd.Parameters.Add("@BIntPreferenceId", SqlDbType.BigInt).Value = objPartnerDetailsInfo.BIntPreferenceId
  8.         cmd.Parameters.Add("@VarPreference", SqlDbType.VarChar).Value = objPartnerDetailsInfo.VarPreference
  9.         cmd.Parameters.Add("@BIntProfileId", SqlDbType.BigInt).Value = objPartnerDetailsInfo.BIntProfileId
  10.         cmd.CommandType = CommandType.StoredProcedure
  11.         cmd.ExecuteNonQuery()
  12.         cmd.Dispose()
  13.         conn.Close()
  14.     End Sub
'following is my stored procedure
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE [dbo].[SPAddEditPartnerDetails]
  2.  
  3.     @operation varchar(50),
  4.     @BIntPartnerDetailsId BIGINT,
  5.     @BIntProfileId BIGINT,
  6.     @BIntPreferenceId bigint,
  7.     @VarPreference varchar(50)
  8. AS
  9. If @operation ='Add'
  10. BEGIN
  11.     Insert tblPartnerDetails
  12.         (
  13.     BIntProfileId,
  14.     BIntPreferenceId,
  15.     VarPreference
  16.         )
  17.     VALUES
  18.         (
  19.     @BIntProfileId,
  20.     @BIntPreferenceId,
  21.     @VarPreference
  22.         )
  23.     Select @BIntPartnerDetailsId=@@Identity
  24.  
  25.     END
  26.  
now i dont know how to fetch data from databse and fill listbox with multiple selected value..
plz give suitable solution..
Jun 30 '10 #1
1 4790
Expand|Select|Wrap|Line Numbers
  1. For intItem As Integer = 0 To lstBox.Items.Count - 1
  2.   For intSel As Integer = 0 To objDT.Rows.Count - 1
  3.     If lstBox.Items(intItem).Value = CInt(objDT.Rows(intSel).Item("Screen_Id")) Then
  4.       lstBox.Items(intItem).Selected = True
  5.     End If
  6.   Next
  7. Next
Jun 30 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Big E | last post by:
I'm using ASP.Net and SQL Server. I have a listbox looks up data from a table and fills the listbox. I have a stored procedure that looks up the selected values and tries to show them as selected...
2
by: Joey | last post by:
Hi There, I am trying to get the selected value of a listbox when I click a button, everything works ok and I can bind the list and when I have a basic page and click a button to invoke a sub it...
5
by: Paul | last post by:
Hi I have a listbox and have the selection mode set to multiple in the property box. I am trying to set multiple selected values in code but it only seems to use the last one....
0
by: Mardy | last post by:
Hello I'm using a multi select listbox that allows the user to select one or more values that are stored in a database. The listbox values are generated from a lookup table (disciplines) and the...
1
by: David J | last post by:
Hi, I am trying again, and seriously struggling. My problem is that I am trying to set the selected value in a listbox equal to a value of a textbox, when you op the listbox. I am not getting that...
1
by: Ben | last post by:
I have a formview with a few dropdownlists (software version, database version, etc). When a software version is selected, the database version dropdownlist updates itself accordingly. When in...
1
by: bbasberg | last post by:
Hello, I am wondering how to "carry over" a value from a listbox on one worksheet in the workbook to a cell in another worksheet in the same workbook. For example, to just copy over a value...
1
by: =?Utf-8?B?R3VzIENodWNo?= | last post by:
I have a ListBox with the SelectionMode set to MultiSimple. How can I iterate thru it using a for next loop to fill an array? Listbox For Row 1 = Array(1) Row 2 = Array(2) Next And so on. --
1
by: hellboss | last post by:
Hi Every one ! im work with asp.net,vs05 My prob is, i have a set of values dynamically binded in listbox control with its datavaluefield to the Corresponding ID and dataTextfield to the text...
1
by: balurbabu | last post by:
I am asp.net 2.0 c#.net, I have a list box,listLocation which allows the user to select mulitple selections. These are stored in a database as comma separated values like bangalore,chennai,delhi...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.