开发者

Still having issues converting VB Webserice to C#.... need help

This webservice is almost converted form VB to C#, except I get this error shown below on the DataRow arow object when I us开发者_开发问答e it in the foreach statement below to populate the Results Class with a DataSet Object... any ideas???

Error: A local variable named 'arow' cannot be declared in this scope because it would give a different meaning to 'arow', which is already used in a 'parent or current' scope to denote something else

        using System;
        using System.Web;
        using System.Collections;
        using System.Web.Services;
        using System.Web.Services.Protocols;
        using System.Data;
        using System.Data.SqlClient;
        using System.Configuration;
        /// <summary>
        /// Summary description for VTResults
        /// </summary>
        [WebService(Namespace = "http://velocitytrading.net/ResultsVT.aspx")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        public class VTResults : System.Web.Services.WebService {
            public class Results {
                public string Ticker;
                public string BuyDate;
                public string Buy;
                public string SellDate;
                public string Sell;
                public string Profit;
                public string Period;
            }
            [WebMethod]
            public Results[] GetResults() {
                string conn = 
                ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
                SqlConnection myconn = new SqlConnection(conn);
                SqlCommand mycomm = new SqlCommand();
                SqlDataAdapter myda = new SqlDataAdapter();
                DataSet myds = new DataSet();

                mycomm.CommandType = CommandType.StoredProcedure;
                mycomm.Connection = myconn;
                mycomm.CommandText = "dbo.Results";

                myconn.Open();
                myda.SelectCommand = mycomm;
                myda.Fill(myds);
                myconn.Close();
                myconn.Dispose();

                int i = 0;

                Results[] dts = new Results[myds.Tables[0].Rows.Count];
                DataRow arow;

                foreach(DataRow arow ** in myds.Tables[0].Rows)
                {
                    dts[i] = new Results();
                    dts[i].Ticker = arow["Ticker"].ToString();
                    dts[i].BuyDate = arow["BuyDate"].ToString();
                    dts[1].Buy = arow["Buy"].ToString();
                    dts[i].SellDate = arow["SellDate"].ToString();
                    dts[i].Sell = arow["Sell"].ToString();
                    dts[i].Profit = arow["Profit"].ToString();
                    dts[i].Period = arow["Period"].ToString();
                    i+=1;
                }
                return dts;
            }    
        }

           ** ERROR ON THIS 'AROW' OBJECT


aRow is being declared twice, once in the foreach and the other right above it. Remove DataRow aRow right above the foreach and you should be good.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜