Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET XML T-SQL
Hi I am passing this xml content as parameter to get a response:
 <COMMAND>
                <TYPE>PAYMENT</TYPE>
                <COMPANYNAME>gemeya</COMPANYNAME>
                <CUSTOMERREFERENCEID>910573404</CUSTOMERREFERENCEID>
                <MSISDN>msisdn</MSISDN>
                <AMOUNT>45150.00</AMOUNT>
                <TXNID></TXNID>
                <STATUS></STATUS>
    </COMMAND>
from a webservice but I am getting this error :
System.IndexOutOfRangeException: Cannot find table 0.
at System.Data.DataTableCollection.get_Item(Int32 index)

 
And the following code is what I am using to test it with information from my db:
 
SP:
01.ALTER PROCEDURE [dbo].[GetCheckoutInfoTest]
02.@Refcode nvarchar(100)
03.,@Amount nvarchar(100)
04.AS
05. BEGIN
06.    DECLARE @Price AS float
07.    DECLARE @RefId AS int
08.    DECLARE @TXTNID AS NVARCHAR(50)
09.    DECLARE @companyname AS NVARCHAR(50)
10.      
11.    SET @Price=(SELECT Amount FROM Checkout  Where Refcode=@Refcode)
12.    SET @RefId=(SELECT Refcode FROM Checkout WHERE Refcode=@Refcode)
13.    SET @TXTNID='GBPHANDLER'
14.    SET @companyname='Gemeya'
15.    if exists(SELECT Amount,Refcode FROM Checkout  Where Refcode=@Refcode)
16.      begin
17.        if(@Amount=@Price and @RefId=@Refcode)
18.        begin
19.          PRINT N'Your transaction successfull. Txn ID:'+ @TXTNID +', reference: '+
20.          @Refcode +', amount :'+ @Amount +' Tsh, Company: '+ @companyname;
21.         return 1
22.        end
23.      end
24.      else
25.      begin
26.       PRINT N'Your transaction Failed';
27.        return 0
28.      end
29. END
in the chekout table I have data...
And this is the class I am using
CS:
01.public class Service : System.Web.Services.WebService
02.{
03.    public int Amount { get; set; }
04.    public int Refcode { get; set; }
05.    public int companycode { get; set; }
06.    public bool IsUsed { get; set; }
07.    public string PhoneNo { get; set; }
08.   #region method constructor
09.    public Service()
10.    {
11.       //Uncomment the following line if using designed components 
12.        //InitializeComponent(); 
13.    }
14.    #endregion
15.    [WebMethod]
16.    public string COMMAND(string xml)
17.    {
18.        #region Load received xml and parse the values
19.        XmlDocument xdoc = new XmlDocument();
20.        xdoc.LoadXml(xml + Environment.NewLine);
21.        string TYPE = xdoc["COMMAND"].ChildNodes[0].InnerText;
22.        string COMPANYNAME = xdoc["COMMAND"].ChildNodes[1].InnerText;
23.        string CUSTOMERREFERENCEID = xdoc["COMMAND"].ChildNodes[2].InnerText;
24.        string MSISDN = xdoc["COMMAND"].ChildNodes[3].InnerText;
25.        string AMOUNT = xdoc["COMMAND"].ChildNodes[4].InnerText;
26.        string TXNID = xdoc["COMMAND"].ChildNodes[5].InnerText;
27.        string STATUS = xdoc["COMMAND"].ChildNodes[6].InnerText;
28.        #endregion
29.       string ERRORCODE = string.Empty;
30.        string RESULT = string.Empty;
31.        string FLAG = string.Empty;
32.        string CONTENT = string.Empty;
33.        //process your code with received information and assign the values of ERRORCODE,RESULT,FLAG,CONTENT
34.        StringBuilder sb = new StringBuilder();
35.        DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), "[GetCheckoutInfoTest]",  
36.        CUSTOMERREFERENCEID,AMOUNT);
37.        if (ds.Tables[0].Rows.Count > 0)
38.        {
39.            //assign the values of ERRORCODE,RESULT,FLAG,CONTENT when condition is true
40.            RESULT = "TS";
41.        }
42.        else
43.        {
44.            //assign the values of ERRORCODE,RESULT,FLAG,CONTENT when condition is false
45.            RESULT = "TF";
46.        }
47. 
48. 
49.        #region write the response xml
50.        XmlWriter writer = XmlWriter.Create(sb);
51. 
52. 
53.            writer.WriteStartDocument();
54.            writer.WriteStartElement("COMMAND");
55.            writer.WriteStartElement("TYPE");
56.            writer.WriteValue(TYPE);
57.            writer.WriteEndElement();
58.            writer.WriteStartElement("TXNID");
59.            writer.WriteValue(TXNID);
60.            writer.WriteEndElement();
61.            writer.WriteStartElement("REFID");
62.            writer.WriteValue(CUSTOMERREFERENCEID);
63.            writer.WriteEndElement();
64.            writer.WriteStartElement("ERRORCODE");
65.            writer.WriteValue(ERRORCODE);
66.            writer.WriteEndElement();
67.            writer.WriteStartElement("FLAG");
68.            writer.WriteValue(FLAG);
69.            writer.WriteEndElement();
70.            writer.WriteStartElement("MSISDN");
71.            writer.WriteValue(MSISDN);
72.            writer.WriteEndElement();
73.            writer.WriteStartElement("CONTENT");
74.            writer.WriteValue(CONTENT);
75.            writer.WriteEndElement();
76.            writer.WriteStartElement("COMPANYCODE");
77.            writer.WriteValue(COMPANYNAME);
78.            writer.WriteEndElement();
79.            writer.WriteStartElement("AMOUNT");
80.            writer.WriteValue(AMOUNT);
81.            writer.WriteEndElement();
82.            writer.WriteEndElement();
83.            writer.WriteEndDocument();
84.            writer.Flush();
85.            #endregion
86.     return sb.ToString();
87.      }
After debug I am getting an error(System.IndexOutOfRangeException) on the line 35.
 
Please help fixing this
Posted 19-Feb-13 1:50am
El Dev823
Edited 19-Feb-13 2:55am
(no name)129.8K
v2
Comments
ryanb31 at 19-Feb-13 7:54am
   
Step into the SQLHelper.ExecuteDataSet to see what is the actual line of code causing it.
El daniel at 19-Feb-13 8:26am
   
I have already step inside.it returning no data in datatable while there is data in the checkout table
ryanb31 at 19-Feb-13 8:28am
   
So, your SQL statement is wrong then?
El daniel at 19-Feb-13 8:37am
   
Yes is why I am asking I want to compare the data send through webservice then test with the data from db.
I can test my sp like this:
DECLARE @return_value int
 
EXEC @return_value = [dbo].[GetCheckoutInfoTest]
@Refcode = N'474879444',
@Amount = N'699150.00'
 
SELECT 'Return Value' = @return_value
 
and it is working but when I am sending this xml

PAYMENT
gemeya
910573404
msisdn
45150.00



it is giving that error...Please help fixing this you can even check my webservice at this url:http://gemeya.com/Webservice.asmx?op=COMMAND and enter the xml content.
ryanb31 at 19-Feb-13 8:38am
   
I would think if you stepped through the code line by line using the debugger, you should be able to see what is different, or even use SQL profiler.
El daniel at 19-Feb-13 8:41am
   
ok tell me do you think the way I am coding is wright because I have already test everything and I do not see what is the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100