Solved

Populate asp:dropdownlist with result from StoredProcedure

Posted on 2008-09-30
1
261 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide vba in gp 7 83
Prevent user closing word document opened with VB6 6 67
Authentication of Web Services 3 54
Output Caching in IIS 2 12
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now