Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

VB.net code to create XML

I am trying to create a web service in visual studio that xcelsius can connect to. I have built the web service using visual studio and the following method:

<WebMethod()> _

Public Function GetDataFromDB() As XmlDocument

Dim errorMessage As String = ""

Dim myDatas As XmlDocument = New XmlDocument()

Dim connectionString As String = ConfigurationManager.ConnectionStrings("LocalCon").ConnectionString

Dim dbConnection As SqlConnection = Nothing

Try

dbConnection = New SqlConnection(connectionString)

dbConnection.Open()

Catch ex As Exception

errorMessage = ex.Message

End Try

If errorMessage = "" Then

Dim SQL As String = "select * From DepotMTD"

Dim GetCustomerCmd As SqlCommand = New SqlCommand(SQL, dbConnection)

Try

Dim custDA As SqlDataAdapter = New SqlDataAdapter()

custDA.SelectCommand = GetCustomerCmd

Dim custDS As Data.DataSet = New Data.DataSet("Dataset")

custDA.Fill(custDS, "Data")

myDatas.LoadXml(custDS.GetXml())

dbConnection.Close()

Catch ex As System.Exception

errorMessage = ex.Message

Finally

dbConnection.Dispose()

End Try

End If

Return myDatas

End Function

This produces the following xml:

<?xml version="1.0" encoding="utf-8" ?>

<Dataset>

<Data>

<Depot>North West</Depot>

<Turnover>21587</Turnover>

</Data>

<Data>

<Depot>North East</Depot>

<Turnover>5698</Turnover>

</Data>

<Data>

<Depot>Central</Depot>

<Turnover>16897</Turnover>

</Data>

<Data>

<Depot>South East</Depot>

<Turnover>22500</Turnover>

</Data>

<Data>

<Depot>South West</Depot>

<Turnover>23564</Turnover>

</Data>

<Data>

<Depot>Scotland</Depot>

<Turnover>25648</Turnover>

</Data>

</Dataset>

Xcelsius cannot read this what do I need to do to my code to correct this?

Any help appreciated.

Regards,

Joe

Former Member
Former Member replied

Below is the c# code snippet. I did not personally write the code.

A developer in my group helped set this up for me to test with xcelsius.

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    public Service()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    public struct EmployeeCount
    {
        public string Company;
        public string eCount;
    }

    [WebMethod]
    public EmployeeCount[] EmployeeCountByCompany()
    {

        string strSQLStatement = "SELECT  ....

(leaving out the actual sql and database connection info that would occur here)

dataAdapterPeopleSoft.Fill(dtOutput);
        connectionPeopleSoft.Close();

        EmployeeCount[] Counts = null;

        int i = 0;
        Counts = new EmployeeCount[dtOutput.Rows.Count];
        foreach (DataRow row in dtOutput.Rows)
        {
            Counts<i>.Company = row["COMPANY"].ToString();
            Counts<i>.eCount = row["EmpCount"].ToString();
            i++;
        }

Basically just getting the data from the database and filling an array with the results. Hope this is helpful.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question