Solved

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

Posted on 2008-10-29
2
186 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
ID: 22834907
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
ID: 22835185
fixed with this :

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

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

929 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

8 Experts available now in Live!

Get 1:1 Help Now