0
이 웹 서비스는 아래의 foreach 문을 사용하여 DataRow arow 개체에이 오류가 표시되는 것을 제외하고는 VB에서 C#으로 거의 변환됩니다 DataSet 객체로 결과 클래스 ... 어떤 아이디어 ???VB Webserice를 C#으로 변환하는 데 여전히 문제가 있습니다.
오류 : 이미 뭔가 다른
을 표시하기 위해 '부모 또는 현재의'범위에 사용되는 '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.NullReferenceException 오류 ... 계속 작업 중 ... 작동하지 않음 – CraigJSte
Datarow arow에 대한 참조를 제거했으며 이 발생합니다. System.NullReferenceException : 개체 참조가 인스턴스로 설정되지 않았습니다. 개체의 at VTResults.GetResult() – CraigJSte
이제 컴파일 오류가 없으므로 런타임 NullReferenceException이 발생합니까? 오류 발생 행은 무엇입니까? 저장 프로 시저가 일부 데이터를 명확하게 반환합니까? 쿼리 분석기에서 실행 한 후 적어도 하나의 행이 반환되었는지 확인 했습니까? arow [ "Ticker"] 등에서 사용중인 필드 이름이 저장 프로 시저에서 반환 한 열의 이름과 일치합니까? – Carson63000