Avatar of J_Kogan
J_Kogan
 asked on

How to populate list box from stored procedure with one parameter?

I have a stored procedure – “SP_Load_ListBox” and one parameter in this stored procedure- @Param.
This stored procedure select two fields – FieldForDataTextfield – field for data text field of my list box and FieldForDataValueField – field for data value field of my list box.
User must enter the parameter value in the textbox1, click button and list box must be populated from this stored procedure with parameter.  
How can I populate my list box from this store procedure with parameter (data text field and data value field of my list box)?

Visual Basic.NETASP.NET

Avatar of undefined
Last Comment
J_Kogan

8/22/2022 - Mon
ErezMor

if you go to "configure data source..." of the listbox, it will take you along a wizard to state the stored proc name, the parameter, and let you set the parameter's source to be a control - which you should set to your textbox.

the point to remember here is that it will run BEFORE the page loads - which means your user didnt have the chance to enter data yet... and therefore - set a default value (in the same step where you connect to the control) - you can set it to something that wouldnt yield any results if you want the list to be empty before the user selected anything
J_Kogan

ASKER
I am sorry, I don't have a wizard, I use VS 2003/VB.NET
Can you give me a code sample?  I need to bind  listbox with store proc.
ASKER CERTIFIED SOLUTION
rajeeshmca

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
J_Kogan

ASKER
Thank you very much.
It works, but in VS2003 I don’t have AddWithValue method, I put:
cmdListBox.Parameters.Add(New SqlParameter("@POST_CODE", SqlDbType.NVarChar, 4))
cmdListBox.Parameters("@POST_CODE").Value = TextBox1.Text

This code didn’t work:
 Dim objDataTable As New DataTable
objSQLDataAdapter.Fill(objDataTable)
ddl.DataSource = objDataTable

I put:
Dim objDataTable As New DataTable
sqaListBox.Fill(dstListBox, "objDataTable")  'dstListBox-dataset
Dim tbTable As New DataTable
tbTable = dstListBox.Tables(0)
lstAppYear.DataSource = tbTable

All the rest code is OK,
Thank you

Your help has saved me hundreds of hours of internet surfing.
fblack61