0
返回多個行我有一個Web服務,它不錯誤,但給我的數據只有一排從web服務
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
namespace nikitaweb
{
/// <summary>
/// Summary description for nikitaws
/// </summary>
[WebService(Namespace = "http://ijportal.kemenkeu.go.id/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class nikitaws : System.Web.Services.WebService
{
public class Stndlist
{
public string nond { get; set; }
public string nost { get; set; }
public string tglst { get; set; }
public string halst { get; set; }
}
[WebMethod]
public Stndlist GetStnd()
{
string CS = ConfigurationManager.ConnectionStrings["nikita_cs"].ConnectionString;
List<Stndlist> Stndlists = new List<Stndlist>();
using (SqlConnection con = new SqlConnection(CS))
{
Stndlist daftarstnd = new Stndlist();
SqlCommand da = new SqlCommand("xp_TampilStNd", con);
da.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader rdr = da.ExecuteReader();
while (rdr.Read())
{
daftarstnd.nond = rdr["nond"].ToString();
daftarstnd.nost = rdr["nost"].ToString();
daftarstnd.tglst = rdr["tglst"].ToString();
daftarstnd.halst = rdr["halst"].ToString();
Stndlists.Add(daftarstnd);
}
//JavaScriptSerializer js = new JavaScriptSerializer();
//Context.Response.Write(js.Serialize(daftarstnd));
return daftarstnd;
}
}
}
}
當我運行web服務只給我一個行
<Stndlist>
<nond>ND-(002)/PP.42/2013</nond>
<nost>ST-(005)/PP/2013</nost>
<tglst>11/26/2013 12:00:00 AM</tglst>
<halst>Usulan Tugas Benchmarking ke Bandung</halst>
</Stndlist>
我的目標是返回我的sql服務器數據庫中的所有行。 你能告訴我如何修改這段代碼? 謝謝。
你有兩個同名的變量。 – mason
@mason,謝謝你指出。 – Sunil