?
Solved

Populating dropdownlists from a webservice - URENT 500 PNT

Posted on 2006-11-15
8
Medium Priority
?
242 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

741 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