SQLDataSource Problem

Eduardo Lorenzo
03-02-2007, 01:16 AM
Hi everyone. Am really new to this SQLDatasourceObject so please bear with my caveman question.

Right now I have this code in the DAL

Public Function GetDataTable(ByVal CommandText As String, ByRef Target As SqlDataSource) As Boolean
Try
thisDatasource.SelectCommand = CommandText
Target = thisDatasource
GetDataTable = True
strErrorMsg = ""
Catch ex As Exception
GetDataTable = False
strErrorMsg = ex.Message
End Try
End Function

the connection string and commandtype are declared as:


Sub New(ByVal ConnectionString As String, ByVal CmdType As SqlDataSourceCommandType)
thisDatasource = New SqlDataSource
thisDatasource.ConnectionString = ConnectionString
thisDatasource.SelectCommandType = CmdType
End Sub


and adding a Select Parameter is like so:

Public Sub addParameter(ByVal paramname As String, ByVal paramval As Object)
thisDatasource.SelectParameters.Add(paramname, paramval)
End Sub

all these functions are in a DAL class called like this:


Public Function getProjectStaff(ByRef target As SqlDataSource, ByVal projectID As String) As Boolean
Dim myhelp As New sqlserverhelper(connstr, SqlDataSourceCommandType.StoredProcedure)
myhelp.addParameter("@projectID", projectID)
If myhelp.GetDataTable("staffPerProject", target) Then
Return True
Else
errormessage = myhelp.ErrorMessage
Return False
End If
myhelp = Nothing
End Function


by the BLL.

The error is triggered here in the Presentation Layer (The page's code behind)

Private Sub loadgrid()
Dim mybll As New PM_BLL
Dim mySource As New SqlDataSource
If mybll.getProjectStaff(mySource, Request.QueryString("ProjectID")) Then
Me.GridView1.DataSource = mySource
Me.GridView1.DataBind() '<---- error is here
End If
End Sub

the code is still pretty much straighforward as I am still just starting this thing.

The error says that the Stored Procedure staffPerProject was expecting the parameter @ProjectID which was not supplied???

BUT!!!! in the GridView1.DataSource = mySource line, mySource.SelectParameters.Count = 1:confused:

All help shall be greatly appreciated.

TIA.

wayneph
03-03-2007, 04:14 AM
If you're doing it in the code behind, don't use the SQLDataSource. Just use a DataTable or something like that. SQLDataSource is intended for being declared in the page.

Since you're using a DAL, you probably want to look into the ObjectDataSource. That will allow you to point the select command (and/or any other command) of your DataSource directly at a method in your DAL. Again, with no specific need for a code behind.

Eduardo Lorenzo
03-04-2007, 03:29 PM
The thing is, the DAL and BLL are scheduled to be exposed via a webservice. The only experience I have with webservices are exposing some rudimentary functions and a dataset. Can't seem to pass a datatable through.

OK, so I should scrap the whole SQLDatasource concept. Architecture dictates that I can't use any form of a datasource on the page itself.

Thanks wayne. You DA MAN!

wayneph
03-05-2007, 08:00 AM
Architecture dictates that I can't use any form of a datasource on the page itself.
What Architecture dictates that? In fact, If you re-read my message, I point you to the ObjectDataSource. You can create an object to interface between your presentation layer and your Web Service.

DataSources are a great tool in 2.0. They greatly assist in your coding. To just say you aren't using them would probably create a lot of extra work for you and be a huge waste of time in the long run.

Eduardo Lorenzo
03-05-2007, 03:46 PM
The architecture they use here where I work now.
It's not n-tier, I don't want to hazard posting a description but they call it the OOP Approach.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum