Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Web Service returning dataset - invalid data src

Author  Topic 

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2006-07-07 : 14:03:24
This is my first attempt at Web Services, and I've tested the actual web service which is working via the Invoke button.

I'm getting the following error when trying to build a ddl from my web service dataset:
An invalid data source is being used for DropDownList1. A valid data source must implement either IListSource or IEnumerable.

The WebReference for the web service is called GetWBS.

The code for the calling page is:
**************************
**************************

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Create an instance of the Proxy class
Dim dsGetWBS As GetWBS.WBSValues
dsGetWBS = New GetWBS.WBSValues

DropDownList1.DataSource = dsGetWBS
DropDownList1.DataBind()
End Sub


I've added a Web Reference, GetWBS, and the code for the .asmx file is:
************************************************************
************************************************************
Public Class WBSValues
<WebMethod()> _
Public Function GetWBS() As DataSet
Dim DS As New DataSet
Try
sCon1.Open()
Dim strSQLType As String = "usp_SelectWBSNumberFromWBSDict"
Dim cmd As New SqlCommand(strSQLType, sCon1)
cmd.CommandType = CommandType.StoredProcedure
'Create the DataAdapter
Dim DA As New SqlDataAdapter
DA.SelectCommand = cmd
'Populate the DataSet and the connection
DA.Fill(DS, "WBSDict")
sCon1.Close()
Return DS
Catch ex As Exception
Throw ex ' = "Error Getting DG data: " & ex.Message
Finally
sCon1.Close()
End Try
End Function
End Class

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-07-07 : 14:31:09
You are not passing a dataset into the datasource of your drop down list. Webservices are like any other class. You create an instance, and call a method to return data. In your example, you are passing an instance of the WebService class into your drop down list, and it's expecting a dataset, thus the Drop Down throws the error you are seeing. Try this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Create an instance of the Proxy class
Dim dsGetWBS As GetWBS.WBSValues
dsGetWBS = New GetWBS.WBSValues

DropDownList1.DataSource = dsGetWBS.GetWBS
DropDownList1.DataBind()
End Sub



Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>

Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Go to Top of Page

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2006-07-07 : 15:12:31
Thanks MichaelP!

That works, but now I get rows of:
system.data.dataview

When I try to assign the datatextfield and datavaluefield, I get
DropDownList1.DataTextField = Expr1 'Expr1 Not declared
DropDownList1.DataValueField = [IDNumber] 'Expression Expected

Expr1 and [IDNumber] are in my sproc called by the web service
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-07-07 : 16:04:27
quote:
Originally posted by bubberz

Thanks MichaelP!

That works, but now I get rows of:
system.data.dataview

When I try to assign the datatextfield and datavaluefield, I get
DropDownList1.DataTextField = Expr1 'Expr1 Not declared
DropDownList1.DataValueField = [IDNumber] 'Expression Expected

Expr1 and [IDNumber] are in my sproc called by the web service



you need to pass in string expressions, not objects, to those properties (note the quotes)

DropDownList1.DataTextField = "Expr1"
DropDownList1.DataValueField = "IDNumber"


- Jeff
Go to Top of Page

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2006-07-07 : 16:37:26
jsmith8858,

Thanks for the reply!

yeah, I realized I was missing the "", and from my original coce added ".Tables(0)" to the datasource.

I've used the following code and now have it working:
'Put user code to initialize the page here
'Create an instance of the Proxy class
Dim dsGetWBS As GetWBS.WBSValues
dsGetWBS = New GetWBS.WBSValues

DropDownList1.DataSource = dsGetWBS.GetWBS.Tables(0)
DropDownList1.DataTextField = "Expr1"
DropDownList1.DataValueField = "WBS Number"
DropDownList1.DataBind()
Go to Top of Page
   

- Advertisement -