× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Yeah sorry figured alot of those out Im not sure if having the method as
string is right for what im wanting to do
One problem im having is that I want multiple values to be returned by
the webservice but this is only returning one here is my altered code



                [WebMethod]
                public string CTX(string filter)
                {
                        try
                        {
                                string result = "Nothing";
                                string result2 = "Still Nothing";
                                iDB2Connection cn = new
iDB2Connection("Datasource=TDC01;userid=RDS;password=sootarsing;DefaultCollection=QGPL;");
                                cn.Open();
                                string sqlstmt = "Select * from ctx4nthg
where REF ='"+@filter+"'";
                                iDB2Command cmd = new
iDB2Command(sqlstmt,cn);
                                iDB2DataReader dr =
cmd.ExecuteReader();
                                int TYPE = dr.GetOrdinal("TYPE");
                                int FUND = dr.GetOrdinal("FUND");

                                while (dr.Read())
                                {
                                 result = (string)dr[TYPE];
                                 result2 = (string)dr[FUND];
                                        //return result;
                                }
                                return result;

                                dr.Close();
                                
                        }
                        catch (Exception e)
                        {
                                return "Error: " + e.Message;   
                        }

>>> jrc@xxxxxxxxxx 10/06/2005 10:16:39 >>>
On Fri, 2005-06-10 at 13:12, Rohan Sootarsing wrote:
> This is what ive tried so far but i am getting an error saying not
all
> code paths return a value

Well, I hate to point out the obvious... but not all your paths return
a
value...

And this has nothing to do with the DataReader, but rather basic C#
language stuff: 

The method returns a string, therefore EVERY possible exit path for
the
method must issue a return string.  In this case, you have defined the
return string inside a try block!  Define the string OUTSIDE the try
block, set an initial value, and then adjust it's value inside the try
block.  Then, make the return statement is the last statement in the
method.

And this below cannot be the entire method... if it is, then you have
no
catch block for your try block, which I don't think will compile, and
if
it will would be entirely useless.

HTH,

Joel Cochran
http://www.rpgnext.com 

> [WebMethod]
> public string CTX(string filter)
> {
>   try
>   {
>       string result = "Nothing";
>       iDB2Connection cn = new
>
iDB2Connection("Datasource=TDC01;userid=RDS;password=sootarsing;DefaultCollection=QGPL;");
>       cn.Open();
>       string sqlstmt = "Select * from ctx4nthg where REF
> ='"+@filter+"'";
>       iDB2Command cmd = new iDB2Command(sqlstmt,cn);
>       iDB2DataReader dr = cmd.ExecuteReader();
>       while (dr.Read())
>       {
>       result = dr.GetString(0);
>       }
>                               
>                return result;
> 
> >>> jrc@xxxxxxxxxx 10/06/2005 09:07:52 >>>
> On Fri, 2005-06-10 at 09:44, Rohan Sootarsing wrote:
> > Hi I am Using a dataset to return data but want to convert this to
> > datareader but can't find much doumentation can anyone help me
here
> is
> > my current code
> > 
> > 
> > iDB2Connection connDB2=new iDB2Connection(
> >   "DataSource=TDC01;" +
> >   "userid=RDS;password=sootarsing;DefaultCollection=QGPL;");
> > DataSet ds = new DataSet();
> > iDB2DataAdapter adpt = new iDB2DataAdapter();
> > string szSQLstmt = "Select * from ctx4nthg where REF ='"
> +@filter+"'";
> > adpt.SelectCommand = new iDB2Command(szSQLstmt,connDB2);
> > adpt.Fill(ds);
> > return ds;
> 
> DataReader is very simple to use:
> 
> <code>
> [create the connection and SQL string as above...]
> iDB2Command cmd = new iDB2Command( sqSQLstmt , connDB2 );
> iDB2DataReader reader = cmd.ExecuteReader();
> while ( reader.Read() )
> {
>       // Process the row
> }
> reader.Close();
> </code>
> 
> Some notes for use: 
> 1) A DataReader has an active database connection, which means it
will
> stay open until you close it.  (This is unlike a DataSet which is
> disconnected).  As a rule of thumb, issue the .Close() method as
soon
> as
> possible.
> 
> 2) To obtain the field data from the current row, you access it like
> an
> array variable, using either the field name or the index number
> (0-based):
> 
>       string field1 = (string)reader[ "FIELD1" ];
>       // or
>       string field1 = (string)reader[ 0 ];
> 
> If you don't know the index numbers, you can retrieve them by using
> the
> GetOrdinal() method:
> 
>       int field1Ordinal = reader.GetOrdinal( "FIELD1" );
> 
> Performance will be much better using ordinal values, so I typically
> capture the ordinals outside the loop and then use them to access
the
> fields:
> 
> <code>
> iDB2Command cmd = new iDB2Command( sqSQLstmt , connDB2 );
> iDB2DataReader reader = cmd.ExecuteReader();
> 
> int field1Ordinal = reader.GetOrdinal( "FIELD1" );
> int field2Ordinal = reader.GetOrdinal( "FIELD2" );
> int field3Ordinal = reader.GetOrdinal( "FIELD3" );
> while ( reader.Read() )
> {
>       string field1 = (string)reader[ field1Ordinal ];
>       int field2 = (int)reader[ field2Ordinal ];
>       string field3 = (string)reader[ field3Ordinal ];
> }
> reader.Close();
> </code>
> 
> 3. Finally, if you are retrieving a single field, look at
> ExecuteScalar
> - it should be lightning fast.
> 
> Hope this helps,
> 
> Joel Cochran
> http://www.rpgnext.com 
> 
> -- 
> This is the Web Enabling the AS400 / iSeries (WEB400) mailing list
> To post a message email: WEB400@xxxxxxxxxxxx 
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/web400 
> or email: WEB400-request@xxxxxxxxxxxx 
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/web400.
> 
>
______________________________________________________________________________
> This email has been checked for viruses by ArmourPlate,
> http://www.armourplate.com, the multi-scanner anti-virus facility
from
> Corpex. 
> 
> 
>
______________________________________________________________________________
> This message has been checked for viruses by Corpex
> using the ArmourPlate Virus Scanning Service. To find out
> how to protect your company visit http://www.armourplate.com 
> or call Corpex on +44 (0)207 430 8000.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.