Solved

Repeater works with sql statement but not with stored procedure?  But stored procedure works alone!

Posted on 2008-10-29
2
185 Views
Last Modified: 2012-05-05
I am trying to use a stored procedure with a repeater

In a previous post I was able to achieve getting the repeater to work with an sql select command, I however cannot get it to work with the stored procedure.  I need to pass in a parameter for the where = part of the select statement.

I will post the working sql command repeater and my failed sproc attempt.
--- working sql command

            Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 
 

                Using myCommand As New SqlCommand("SELECT UserId, ProfileName, RealName, Age from ag_profiles", myConnection)
 

                    myConnection.Open()
 

                    Dim dr As SqlDataReader = myCommand.ExecuteReader()
 

                    ListProfiles.DataSource = dr
 

                    While (dr.Read())
 

                        ListProfiles.DataBind()
 

                    End While
 

                    dr.Close()
 

                    myConnection.Close()

                End Using

            End Using
 

---- Fail stored procedure

Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 

                Using myCommand As New SqlCommand("AGProfileSearchName", myConnection)
 

                    myCommand.CommandType = CommandType.StoredProcedure
 

                    myConnection.Open()
 

                    myCommand.Parameters.AddWithValue("@SearchName", SearchName)
 

                    Dim dr As SqlDataReader = myCommand.ExecuteReader()
 

                    ListProfiles.DataSource = dr
 

                    While (dr.Read())

                        UserIdLabel.Text = dr("UserId").ToString().Trim()
 
 

                        ListProfiles.DataBind()
 

                    End While
 

                    dr.Close()
 

                    myConnection.Close()

                End Using

            End Using

Open in new window

0
Comment
Question by:HarleySkater
  • 2
2 Comments
 
LVL 1

Author Comment

by:HarleySkater
Comment Utility
I got this working with a stored procedure, but I can't get it to work with a stored procedure that has a parameter?????

  if I use a stored procedure with a parameter it throws an error at: da.Fill(ProfileSearchResultSet)
saying:

System.Data.SqlClient.SqlException was unhandled by user code
  Class=16
  ErrorCode=-2146232060
  LineNumber=0
  Message="Procedure or function 'AGProfileSearchName' expects parameter '@SearchName', which was not supplied."
  Number=201
  Procedure="AGProfileSearchName"
  Server="ACF000\SQLEXPRESS"
  Source=".Net SqlClient Data Provider"
  State=4
 
            Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("AGConnectionString").ConnectionString)
 

                Using myCommand As New SqlCommand("AGProfileSearchName", myConnection)
 
 

                    myCommand.CommandType = CommandType.StoredProcedure

                    myCommand.Parameters.AddWithValue("@SearchName", "a")
 
 

                    myConnection.Open()
 
 

                    Using da As New SqlDataAdapter("AGProfileSearchName", myConnection)
 

                        da.Fill(ProfileSearchResultSet)

                    End Using
 

                    myConnection.Close()

                End Using
 
 

                'ASP Repeater with an Id of "ListProfilesRepeater"

                Me.ListProfilesRepeater.DataSource = ProfileSearchResultSet.Tables(0)

                Me.ListProfilesRepeater.DataBind()
 

            End Using

Open in new window

0
 
LVL 1

Accepted Solution

by:
HarleySkater earned 0 total points
Comment Utility
fixed with this :

                    Using da As New SqlDataAdapter("AGProfileSearchName", myConnection)
                        da.SelectCommand = myCommand
                        da.Fill(ProfileSearchResultSet)
                    End Using
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

762 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

11 Experts available now in Live!

Get 1:1 Help Now