Solved

Populating dropdownlists from a webservice - URENT 500 PNT

Posted on 2006-11-15
8
240 Views
Last Modified: 2012-08-13
Hi in the passed i have populated dropdown lists by:

Dim connectionStringa As String = "Provider=SQLOLEDB; Data Source=#####; Initial Catalog=####; User ID=#### Password=####;"
        Dim fulluser As String = userstring

        Dim conna As New OleDb.OleDbConnection(connectionStringa)
        Dim strSQLa As String
        strSQLa = "SELECT usernumber, rssfeedurl, rssdfeedtitle FROM userrssfeed  WHERE usernumber= " & " '" & Label1.Text & "'" & ""
        Dim cmda As New OleDb.OleDbCommand(strSQLa, conna)
        Dim dataAdapter As New OleDb.OleDbDataAdapter(cmda)
        Dim dt As New DataTable
        conna.Open()
        dataAdapter.Fill(dt)
        conna.Close()
        DropDownList1.DataSource = dt

        DropDownList1.DataTextField = "rssdfeedtitle"
        DropDownList1.DataValueField = "rssfeedurl"
        DropDownList1.DataBind()
        DropDownList1.Items.Add("Select the RSS feed you wish to view from this list box")
        DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText("Select the RSS feed you wish to view from this list box"))
        conna.Close()


Now i have 2 questions:

First of all how can i in a web service expose the results of a query like this:   strSQLa = "SELECT usernumber, rssfeedurl, rssdfeedtitle FROM userrssfeed  WHERE usernumber= " & " '" & Label1.Text & "'" & ""

secondly how can i populate a dropdown list using a web serivece, both the textfield and value f
0
Comment
Question by:fedders_world
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17945810
You could just have your WebService return a DataTable which you can then bind to, and pass your Label1.Text as a parameter:

    Public Function GetRssDetails(UserNumber As String) As DataTable

        Dim conna As New OleDb.OleDbConnection(connectionStringa)
        Dim strSQLa As String
        strSQLa = "SELECT usernumber, rssfeedurl, rssdfeedtitle FROM userrssfeed  WHERE usernumber= " & " '" & UserNumber & "'"
        Dim cmda As New OleDb.OleDbCommand(strSQLa, conna)
        Dim dataAdapter As New OleDb.OleDbDataAdapter(cmda)
        Dim dt As New DataTable
        conna.Open()
        dataAdapter.Fill(dt)

        Return dt

    End Function

Then bind to it like:

    DropDownList1.DataSource = myWebService.GetRssDetails( Label1.Text )
    DropDownList1.DataTextField = "rssdfeedtitle"
    DropDownList1.DataValueField = "rssfeedurl"
    DropDownList1.DataBind()
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 17945964
Hi fedders_world,

and another thing in addition to carl_tawn reply
if you have use your web service in .net 1.1 you can not pass datatable as result because it can not be serialized
in this scenario you will have to use dataset instead of datatable object and then you will have to modify the datasource line like
DropDownList1.DataSource = myWebService.GetRssDetails( Label1.Text ).Tables(0)

Cheers!
0
 

Author Comment

by:fedders_world
ID: 17946329
Thanks so far!!

i've tries what you said:

  Public Function get_user_feeds(ByVal session As String) As DataTable

        Dim uidapi As New user_api.user_account
        Dim getuid As String = uidapi.get_uidfrom_session(session)
        Dim strSQLpass As String
        Dim connectionStringpass As String = "Provider=SQLOLEDB; Data Source=###,4656; Initial Catalog=###; User ID=###; Password=###;"

        Dim conna As New OleDb.OleDbConnection(connectionStringpass)

        strSQLpass = "SELECT id, Uid, Ftitle FROM RSSflib_Table WHERE Uid= " & " '" & getuid & "'" & ""

        Dim cmda As New OleDb.OleDbCommand(strSQLpass, conna)
        Dim dataAdapter As New OleDb.OleDbDataAdapter(cmda)
        Dim dt As New DataTable
        conna.Open()
        dataAdapter.Fill(dt)

        Return dt


    End Function


ANYWAY, when i try that i get this error:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Cannot serialize the DataTable. DataTable name is not set.
   at System.Data.DataTable.WriteXmlSchema(XmlWriter writer, Boolean writeHierarchy)
   at System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter writer)
   at System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_DataTable(Object o)
   at Microsoft.Xml.Serialization.GeneratedAssembly.DataTableSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
   at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
   at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
   at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
   at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
   at System.Web.Services.Protocols.WebServiceHandler.Invoke()


any idea why? Btw im using VS 2005, with VB, .NET framework 2 (Asp.net)

thanks again :)
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 28

Expert Comment

by:mmarinov
ID: 17946406
Have you tried the dataset suggestion i have posted?
regards
0
 

Author Comment

by:fedders_world
ID: 17946417
im a little new to all this, how would i use a dataset?
thanks

feds
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 500 total points
ID: 17946424
Public Function get_user_feeds(ByVal session As String) As DataSet

        Dim uidapi As New user_api.user_account
        Dim getuid As String = uidapi.get_uidfrom_session(session)
        Dim strSQLpass As String
        Dim connectionStringpass As String = "Provider=SQLOLEDB; Data Source=###,4656; Initial Catalog=###; User ID=###; Password=###;"

        Dim conna As New OleDb.OleDbConnection(connectionStringpass)

        strSQLpass = "SELECT id, Uid, Ftitle FROM RSSflib_Table WHERE Uid= " & " '" & getuid & "'" & ""

        Dim cmda As New OleDb.OleDbCommand(strSQLpass, conna)
        Dim dataAdapter As New OleDb.OleDbDataAdapter(cmda)
        Dim ds As New DataSet
        conna.Open()
        dataAdapter.Fill(ds)

        Return ds


    End Function
0
 

Author Comment

by:fedders_world
ID: 17946456
HAH!!

It works, but i have not yet tried populating a dropdown box. Just a quick question before i do. What is the reson behind the '.Tables(0) in
DropDownList1.DataSource = myWebService.GetRssDetails( Label1.Text ).Tables(0)

feds
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 17946471
this gets the first table from the dataset object - it equal to myWebService.GetRssDetails( Label1.Text ) if the method returns datatable
0

Featured Post

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!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

729 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