setting datasource params

I have the following functions inside my class.

 Private Sub GetData()
        Select Case _strRequired
            Case "FirstTeamFixtures"
                _dsData.SelectCommand = "SP_TEAM_FIXTURES"
                _dsData.SelectParameters.Add("@Team", "FIRST")
                _dsData.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
                _dsData.ConnectionString = "xyz"
            Case "FirstTeamResults"

            Case "FirstTeamLeagueTable"

            Case "FirstTeamStatistics"
        End Select
    End Sub

The_dsData is then returned as a property of the class as a datasource.

It is then used in the code behind my page as :
dsDataDisplay.SelectParameters.Add(_FixtureResult.DataSource.SelectParameters(0))

(_FixtureResult.DataSource.SelectParameters(0)) IS A RESULT OF THE CODE ABOVE.

However when i run this i am being told that:
'SP_TEAM_FIXTURES' expects parameter '@Team', which was not supplied.

Can any1 see why this is occuring?

Thanks in advance
scm0smlAsked:
Who is Participating?
 
VICKRAMConnect With a Mentor Commented:
Like I said.. Did you try this in your original code (the code posted in your quesion) above? i.e., without "@"

_dsData.SelectParameters.Add("Team", "FIRST")
0
 
VICKRAMCommented:
Try instantiating a parameter like this...

Dim sqlParam As SqlParameter = New SqlParameter ("@Team", SqlDbType.VarChar)
sqlParam.Value = "FIRST"

..and add it to the SelectParameters collection
_dsData.SelectParameters.Add(sqlParam)
0
 
scm0smlAuthor Commented:
Error      1      Value of type 'System.Data.SqlClient.SqlParameter' cannot be converted to 'System.Web.UI.WebControls.Parameter'.      C:\Users\Simon\Documents\Visual Studio 2005\WebSites\TaffsWellAFC\App_Code\FixtureResultContent.vb      78      46      C:\...\TaffsWellAFC\


I GET THIS WHEN TRYING TO ADD THE PARAMETER I HAVE CREATED?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
scm0smlAuthor Commented:
Dim sqlParam As SqlParameter = New SqlParameter("@Team", SqlDbType.VarChar)
                sqlParam.Value = "FIRST"

                _dsData.SelectCommand = "SP_TEAM_FIXTURES"                
                _dsData.SelectParameters.Add(sqlParam)
0
 
SammyConnect With a Mentor Commented:
SqlParameter class have multiple constructors
one of them accepts the following params ParamName, DataType, Size and finally the value

_dsData.SelectCommand.Parameters.Add("@Team", SqlDbType.VarChar, 80).Value = "First")

here is the class docs

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter(vs.80).aspx

0
 
VICKRAMCommented:
What is _dsData? what kind of control is it?
0
 
scm0smlAuthor Commented:
Dim _dsData As New SqlDataSource
0
 
VICKRAMCommented:
_dsData.SelectParameters["Team"].DefaultValue="FIRST"
0
 
scm0smlAuthor Commented:
I dont get that option in my intellisense, do i need to import something other than:
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
0
 
VICKRAMCommented:
What I gave is C# code. I am not familiar with VB.NET. I guess you should use '(' instead of '['

_dsData.SelectParameters("Team").DefaultValue="FIRST"
0
 
scm0smlAuthor Commented:
now im getting:
Object reference not set to an instance of an object.

at line:
_dsData.SelectParameters("Team").DefaultValue = "FIRST"
0
 
scm0smlAuthor Commented:
is that relating to the parameter?
0
 
VICKRAMCommented:
Did you try this in your original code? i.e., without "@"

_dsData.SelectParameters.Add("Team", "FIRST")
0
 
SammyCommented:
>>now im getting:
Object reference not set to an instance of an object.

at line:
_dsData.SelectParameters("Team").DefaultValue = "FIRST"
there reason you are getting this is the fact you are not setting the parameter in your aspx file

I think there is a confusion here between SqlParameters and SqlDataSource parameters
SqlDataSource parameters HAVE to be declared in the aspx file
0
 
scm0smlAuthor Commented:
This getting far more complicated than it should be.

I'm new to .net 2.0.

All i want to do is pass in a variable into a stored procedure and display the results in a gridview.

Would you be able to give me a brief bullet point list of what is the best way to do this.
0
 
scm0smlAuthor Commented:
yeah thats worked fine now.

As VICKRAM gave me most of the answers that actually led to solution I have given him most of the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.