Solved

Populate asp:dropdownlist with result from StoredProcedure

Posted on 2008-09-30
1
265 Views
Last Modified: 2012-06-27
I have a form with some fields to take input from a user in order to generate a report.
I have a Start and End Date date range, which are parameters to a stored procedure to return the available values in an asp:dropdownlist, for clientname and clientid as the value field.
Eventually, I would like to retrieve the values from javascript calendar selections;
But for now, I would just like this code to work with hard-coded values.....
I hard-coded my start and end date as:  '01/01/2008' and '02/02/2009'.
Attached is my code; but the error is:
Procedure or function 'rsp_cc_clienttype' expects parameter '@startdate', which was not supplied.
But, when I step thru the debugger I set up the parameters correctly AND I think my syntax is correct.

Please Help-
John



Sub GetData()
            Dim ds As New DataSet
            Using da As New SqlClient.SqlDataAdapter("rsp_cc_clienttype", objConn)
                Dim myComm1 As New SqlCommand("rsp_cc_clienttype", objConn)
 
                myComm1.Parameters.Add("@startdate", SqlDbType.SmallDateTime, 6).Value = sdate
                myComm1.Parameters.Add("@enddate", SqlDbType.SmallDateTime, 6).Value = edate
 
                myComm1.CommandType = CommandType.StoredProcedure
 
                da.Fill(ds)
 
                myComm1.ExecuteNonQuery()
 
                'fill clients
                With ddClient
                    .Items.Clear()
                    .DataSource = ds.Tables(0)
                    .DataValueField = "clientid"
                    .DataTextField = "clientname"
                    .DataBind()
                End With
 
                If objConn.State <> ConnectionState.Closed Then
                    objConn.Close()
                End If
                'End Try
            End Using
        End Sub

Open in new window

0
Comment
Question by:jtrapat1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 22615036
Try this:
Sub GetData()
	Dim ds As New DataSet
	Dim da As New SqlClient.SqlDataAdapter
	
	Dim myComm1 As New SqlCommand("rsp_cc_clienttype", objConn)
	myComm1.CommandType = CommandType.StoredProcedure
	da.SelectCommand = myComm1
	da.SelectCommand.Parameters.AddWithValue("@startdate", sdate)
	da.SelectCommand.Parameters.AddWithValue("@enddate", edate)
 
	da.Fill(ds)
 
	'fill clients
	With ddClient
		.Items.Clear()
		.DataSource = ds.Tables(0)
		.DataValueField = "clientid"
		.DataTextField = "clientname"
		.DataBind()
	End With
	
	da.Dispose()	
End Sub

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question