Solved

Populating dropdownlists from a webservice - URENT 500 PNT

Posted on 2006-11-15
8
232 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
  • 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
 
LVL 28

Expert Comment

by:mmarinov
ID: 17946406
Have you tried the dataset suggestion i have posted?
regards
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now