473,396 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Reading Data to Public class from database to VB Webservice

Hi,

I've been pulling my hair out over a problem and I'm sure its my lack of experience and probably easily answered. I've done a lot of searching but I'm probably not clued up enough to know what I'm actually looking for.

I'm creating an XML web service, which is reading data from a MySQL database. I just cant seem to get the value from the database into Class for the xml - keep getting direct cast errors (which I dont understand)or when I try a different way I'm now getting "Value of type 'String' cannot be converted to Soap.Topic"

Here's relevant bits of my code, please help!

Expand|Select|Wrap|Line Numbers
  1. <WebMethod()> _
  2.     Public Function Categories() As Topics
  3.         Dim CG As New Topics
  4. Dim Temp As New ArrayList
  5.         Dim count As Integer = 0
  6.         SQLConnection.ConnectionString = ServerString
  7.         Try
  8.             If SQLConnection.State = ConnectionState.Closed Then
  9.  
  10.                 strQuery = "SELECT categories.Name " & _
  11.                 "FROM categories"
  12.                 SQLCmd = New MySqlCommand(strQuery, SQLConnection)
  13.                 SQLConnection.Open()
  14.                 DR = SQLCmd.ExecuteReader
  15.  Do While (DR.Read())
  16.                     Temp.Add(DR.Item("name"))
  17.                 Loop
  18.                 count = 0
  19.                 For Each dato As String In Temp
  20.                     CG.Category(count) = dato
  21.                     count = count + 1
  22.                 Next
  23.                 CG.Result = ("Successfully read")
  24.                 DR.Close()
  25.                 SQLConnection.Close()
  26.             Else
  27.                 SQLConnection.Close()
  28.                 Result = ("Connection is Closed.")
  29.             End If
  30.         Catch ex As Exception
  31.             CG.Result = (ex.ToString)
  32.         End Try
  33.         Return CG
  34.     End Function
  35. Public Class Topics
  36.     Public Category() As Topic
  37.     Public Result As String
  38. End Class
  39. Public Class Topic
  40.     Public Top As String
  41. End Class
  42.  
Dec 6 '11 #1
4 1970
markmcgookin
648 Expert 512MB
John (Remember me? Saw this on fb and thought I would pop on and help)

So from what I gather, you are retrieving your string successfully from your database, but in sending in a SOAP packet you are running into an issue? Is that right?
Dec 7 '11 #2
I do indeed mate. Thanks very much! The power of social networks eh?

As usual I wont have explained it very well. Please bear in mind I've not done any coding since being a student and even then it was only Pascal so I may have some fundamentals very wrong.

I've defined the XML object for the SOAP packet as Public class. One the XML elements that gets populated is called categories, of which there can be many so I set this xml class element as an array. I called a new instance of the xml in the main code (I think I may have done this wrong) and I can't get it to populate with data that I've read from a database and added to a listarray. All the messages seem to indicate its the wrong data types, or I've created the object wrong. Sorry can't really explain it better than that.

If you have time I've popped the project on my public dropbox at:
http://dl.dropbox.com/u/14603871/TestSoap.zip

You'll probably be able to see much better than I can explain, if you just take the MySQL read out and instead populate the listarray with the typical content the DB has such as Web, Mobile, etc.

Will find a way to buy you xmas beer if you can help :) I'm sure I'm just doing something really dumb but I've kind of jumped in at the deep end rather than trying to learn VB from the ground up.
Dec 7 '11 #3
A colleagues come in and helped me. As I thought it was me being dumb. Simply changing the Public class topics.category to an ArrayList rather than an array and changed the read to:

CG.Category = New ArrayList
Do While (DR.Read())
'Temp.Add(DR.Item("name"))
CG.Category.Add(DR.Item("name"))
Loop

Thanks very much for trying to help Mark, much appreciated!
Dec 7 '11 #4
markmcgookin
648 Expert 512MB
lol np, just back from lunch and about to look at it for you.

Array in VB is probably static, and an ArrayList will grow in size, like a Vector.

Glad you got it sorted.
Dec 7 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dariusz | last post by:
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem...
0
by: Andy | last post by:
Hi, In the code below (not pretty I know but it's an early version :-P) I'm having problems reading the data object back in. If I move the reading code to immediately after the section where it...
0
by: John Bailo | last post by:
Wow, I just figured out some cool stuff thanks to Ken Kolda in m.p.d.f.remoting Now I have my multiuser XmlDocument set to load once at startup using a static invocation of a class. Next I'll...
2
by: Goran | last post by:
I'm a student and I've just started to learn Visual Studio.NET. I have a project to make a web application. I have a problem to connect to the database and retriving the PassType of the...
9
by: Ed Gonen | last post by:
Hi, I have the following problem. I've created 2 WebServices (A and B) that reference to the same assembly - Credentials. Each WebService (A and B) expose method GetCredentials that returns the...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
9
by: gavy7210 | last post by:
hello friends i am new to struts. i want to add the user information in the database and then display it back to him. i am using struts 1.2,Eclipse Platform Version: 3.4.2,mySql 5.0.1,jdk...
1
by: dotnetnovice | last post by:
Hi dear fellows...i am a newbie in C# and practicing it hardly to learn it. Actually i am reading a table from data base through data reader and displaying it in the gridview and i am doing well...
0
by: electrical | last post by:
/** Database implements a database of records */ public class Database { private Record base; // the collection of records private int NOT_FOUND = -1; // int used to denote when a...
5
by: khushboosoni | last post by:
The error is "There was an error generating the XML document.". I think there is no need to serialize a class before sending it to a webservice.But im not sure of nested classes.Please give me some...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.