Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将VB Webserice转换为C#时仍然存在问题。。。。需要帮助吗_C#_Vb.net_Web Services - Fatal编程技术网

将VB Webserice转换为C#时仍然存在问题。。。。需要帮助吗

将VB Webserice转换为C#时仍然存在问题。。。。需要帮助吗,c#,vb.net,web-services,C#,Vb.net,Web Services,此Web服务几乎从VB转换为C#,除了我在下面的foreach语句中使用DataRow arow对象来用DataSet对象填充Results类时,在DataRow arow对象上出现以下错误。。。有什么想法吗 错误:无法在此作用域中声明名为“arow”的局部变量,因为它将赋予“arow”不同的含义,而“arow”已在“父或当前”作用域中用于表示其他内容 using System; using System.Web; using System.Col

此Web服务几乎从VB转换为C#,除了我在下面的foreach语句中使用DataRow arow对象来用DataSet对象填充Results类时,在DataRow arow对象上出现以下错误。。。有什么想法吗

错误:无法在此作用域中声明名为“arow”的局部变量,因为它将赋予“arow”不同的含义,而“arow”已在“父或当前”作用域中用于表示其他内容

        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
使用系统;
使用System.Web;
使用系统集合;
使用System.Web.Services;
使用System.Web.Services.Protocols;
使用系统数据;
使用System.Data.SqlClient;
使用系统配置;
/// 
///VTS结果的摘要说明
/// 
[WebService(命名空间=”http://velocitytrading.net/ResultsVT.aspx")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
公共类VTResults:System.Web.Services.WebService{
公开课成绩{
公共字符串记录器;
公共字符串购买日期;
公共字符串购买;
公共字符串日期;
公开发售;
公共利益;
公共字符串周期;
}
[网络方法]
公共结果[]GetResults(){
字符串连接=
ConfigurationManager.ConnectionString[“LocalSqlServer”].ConnectionString;
SqlConnection myconn=新的SqlConnection(conn);
SqlCommand mycmm=新的SqlCommand();
SqlDataAdapter myda=新的SqlDataAdapter();
数据集myds=新数据集();
mycomm.CommandType=CommandType.storedProcess;
mycomm.Connection=myconn;
mycomm.CommandText=“dbo.Results”;
myconn.Open();
myda.SelectCommand=mycmm;
myda.Fill(myds);
myconn.Close();
myconn.Dispose();
int i=0;
Results[]dts=新结果[myds.Tables[0].Rows.Count];
数据行arow;
foreach(myds.Tables[0].Rows中的DataRow**行)
{
dts[i]=新结果();
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;
}
返回dts;
}    
}
**此“AROW”对象出错

aRow
被声明两次,一次在
foreach
中,另一次在其右上方。在foreach的正上方删除
DataRow
,您应该很好。

System.NullReferenceException错误。。。继续尝试消除此错误。。。不工作我已经删除了对Datarow的引用,我得到一个System.NullReferenceException:对象引用未设置为对象的实例。在VTResults.GetResult()处,您现在没有编译错误,只有运行时NullReferenceException?错误发生在哪一行?存储过程是否确实返回了一些数据?您是否在查询分析器中运行它并验证它是否至少返回了一行?arow[“Ticker”]等行中使用的字段名是否与存储过程返回的列的名称完全匹配?它作为数据集运行良好,但当我尝试使用结果类作为数据模型来获取规范化的XML时,它不会运行。发现问题。。。dts[1].Buy=arow[“Buy”].ToString();应该是dts[我]!!!!!!!!!!!!!!!!!!!