Solved

Populating dropdownlists from a webservice - URENT 500 PNT

Posted on 2006-11-15
8
235 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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