[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

setting datasource params

Posted on 2007-10-14
16
Medium Priority
?
445 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:scm0sml
  • 8
  • 6
  • 2
16 Comments
 
LVL 13

Expert Comment

by:VICKRAM
ID: 20074462
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
 

Author Comment

by:scm0sml
ID: 20074485
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
 

Author Comment

by:scm0sml
ID: 20074487
Dim sqlParam As SqlParameter = New SqlParameter("@Team", SqlDbType.VarChar)
                sqlParam.Value = "FIRST"

                _dsData.SelectCommand = "SP_TEAM_FIXTURES"                
                _dsData.SelectParameters.Add(sqlParam)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Assisted Solution

by:Sammy Ageil
Sammy Ageil earned 600 total points
ID: 20074492
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
 
LVL 13

Expert Comment

by:VICKRAM
ID: 20074497
What is _dsData? what kind of control is it?
0
 

Author Comment

by:scm0sml
ID: 20074505
Dim _dsData As New SqlDataSource
0
 
LVL 13

Expert Comment

by:VICKRAM
ID: 20074518
_dsData.SelectParameters["Team"].DefaultValue="FIRST"
0
 

Author Comment

by:scm0sml
ID: 20074527
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
 
LVL 13

Expert Comment

by:VICKRAM
ID: 20074551
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
 

Author Comment

by:scm0sml
ID: 20074591
now im getting:
Object reference not set to an instance of an object.

at line:
_dsData.SelectParameters("Team").DefaultValue = "FIRST"
0
 

Author Comment

by:scm0sml
ID: 20074593
is that relating to the parameter?
0
 
LVL 13

Expert Comment

by:VICKRAM
ID: 20075753
Did you try this in your original code? i.e., without "@"

_dsData.SelectParameters.Add("Team", "FIRST")
0
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 20075854
>>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
 

Author Comment

by:scm0sml
ID: 20080208
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
 
LVL 13

Accepted Solution

by:
VICKRAM earned 1400 total points
ID: 20080247
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
 

Author Comment

by:scm0sml
ID: 20080308
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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.
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

831 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