fedders_world
asked on
Populating dropdownlists from a webservice - URENT 500 PNT
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(conn ectionStri nga)
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(cmd a)
Dim dt As New DataTable
conna.Open()
dataAdapter.Fill(dt)
conna.Close()
DropDownList1.DataSource = dt
DropDownList1.DataTextFiel d = "rssdfeedtitle"
DropDownList1.DataValueFie ld = "rssfeedurl"
DropDownList1.DataBind()
DropDownList1.Items.Add("S elect the RSS feed you wish to view from this list box")
DropDownList1.SelectedInde x = DropDownList1.Items.IndexO f(DropDown List1.Item s.FindByTe xt("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
Dim connectionStringa As String = "Provider=SQLOLEDB; Data Source=#####; Initial Catalog=####; User ID=#### Password=####;"
Dim fulluser As String = userstring
Dim conna As New OleDb.OleDbConnection(conn
Dim strSQLa As String
strSQLa = "SELECT usernumber, rssfeedurl, rssdfeedtitle FROM userrssfeed WHERE usernumber= " & " '" & Label1.Text & "'" & ""
Dim cmda As New OleDb.OleDbCommand(strSQLa
Dim dataAdapter As New OleDb.OleDbDataAdapter(cmd
Dim dt As New DataTable
conna.Open()
dataAdapter.Fill(dt)
conna.Close()
DropDownList1.DataSource = dt
DropDownList1.DataTextFiel
DropDownList1.DataValueFie
DropDownList1.DataBind()
DropDownList1.Items.Add("S
DropDownList1.SelectedInde
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
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!
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
Cheers!
ASKER
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(conn ectionStri ngpass)
strSQLpass = "SELECT id, Uid, Ftitle FROM RSSflib_Table WHERE Uid= " & " '" & getuid & "'" & ""
Dim cmda As New OleDb.OleDbCommand(strSQLp ass, conna)
Dim dataAdapter As New OleDb.OleDbDataAdapter(cmd a)
Dim dt As New DataTable
conna.Open()
dataAdapter.Fill(dt)
Return dt
End Function
ANYWAY, when i try that i get this error:
System.InvalidOperationExc eption: There was an error generating the XML document. ---> System.InvalidOperationExc eption: Cannot serialize the DataTable. DataTable name is not set.
at System.Data.DataTable.Writ eXmlSchema (XmlWriter writer, Boolean writeHierarchy)
at System.Data.DataTable.Syst em.Xml.Ser ialization .IXmlSeria lizable.Wr iteXml(Xml Writer writer)
at System.Xml.Serialization.X mlSerializ ationWrite r.WriteSer ializable( IXmlSerial izable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)
at Microsoft.Xml.Serializatio n.Generate dAssembly. XmlSeriali zationWrit er1.Write3 _DataTable (Object o)
at Microsoft.Xml.Serializatio n.Generate dAssembly. DataTableS erializer. Serialize( Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.X mlSerializ er.Seriali ze(XmlWrit er xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.X mlSerializ er.Seriali ze(XmlWrit er xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.X mlSerializ er.Seriali ze(TextWri ter textWriter, Object o)
at System.Web.Services.Protoc ols.XmlRet urnWriter. Write(Http Response response, Stream outputStream, Object returnValue)
at System.Web.Services.Protoc ols.HttpSe rverProtoc ol.WriteRe turns(Obje ct[] returnValues, Stream outputStream)
at System.Web.Services.Protoc ols.WebSer viceHandle r.WriteRet urns(Objec t[] returnValues)
at System.Web.Services.Protoc ols.WebSer viceHandle r.Invoke()
any idea why? Btw im using VS 2005, with VB, .NET framework 2 (Asp.net)
thanks again :)
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
Dim strSQLpass As String
Dim connectionStringpass As String = "Provider=SQLOLEDB; Data Source=###,4656; Initial Catalog=###; User ID=###; Password=###;"
Dim conna As New OleDb.OleDbConnection(conn
strSQLpass = "SELECT id, Uid, Ftitle FROM RSSflib_Table WHERE Uid= " & " '" & getuid & "'" & ""
Dim cmda As New OleDb.OleDbCommand(strSQLp
Dim dataAdapter As New OleDb.OleDbDataAdapter(cmd
Dim dt As New DataTable
conna.Open()
dataAdapter.Fill(dt)
Return dt
End Function
ANYWAY, when i try that i get this error:
System.InvalidOperationExc
at System.Data.DataTable.Writ
at System.Data.DataTable.Syst
at System.Xml.Serialization.X
at Microsoft.Xml.Serializatio
at Microsoft.Xml.Serializatio
at System.Xml.Serialization.X
--- End of inner exception stack trace ---
at System.Xml.Serialization.X
at System.Xml.Serialization.X
at System.Web.Services.Protoc
at System.Web.Services.Protoc
at System.Web.Services.Protoc
at System.Web.Services.Protoc
any idea why? Btw im using VS 2005, with VB, .NET framework 2 (Asp.net)
thanks again :)
Have you tried the dataset suggestion i have posted?
regards
regards
ASKER
im a little new to all this, how would i use a dataset?
thanks
feds
thanks
feds
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
feds
this gets the first table from the dataset object - it equal to myWebService.GetRssDetails ( Label1.Text ) if the method returns datatable
Public Function GetRssDetails(UserNumber As String) As DataTable
Dim conna As New OleDb.OleDbConnection(conn
Dim strSQLa As String
strSQLa = "SELECT usernumber, rssfeedurl, rssdfeedtitle FROM userrssfeed WHERE usernumber= " & " '" & UserNumber & "'"
Dim cmda As New OleDb.OleDbCommand(strSQLa
Dim dataAdapter As New OleDb.OleDbDataAdapter(cmd
Dim dt As New DataTable
conna.Open()
dataAdapter.Fill(dt)
Return dt
End Function
Then bind to it like:
DropDownList1.DataSource = myWebService.GetRssDetails
DropDownList1.DataTextFiel
DropDownList1.DataValueFie
DropDownList1.DataBind()