我想從Web服務中的SQL Server中檢索多行。當我搜索jo number 1並且我的表名是TestOrderStatus
時,我得到2行。在Web服務和xamarin android中從SQL Server檢索多行?
雖然我在搜索結果中只有一行。
感謝所有
public class ReturnOrder
{
public string Message;
public int QtqSlit;
public int QtyPcs;
public string Design;
}
[WebMethod(MessageName = "OrderStatus", Description = "OrderStatus new Order")]
[System.Xml.Serialization.XmlInclude(typeof(ReturnOrder))]
public ReturnOrder OrderStatus(string JO) /// get list of notes
{
int QtqSlit = 0;
int QtyPcs = 0;
String Design = "";
string Message = "";
SqlDataReader reader;
using (SqlConnection connection = new SqlConnection(DBConnection.ConnectionString))
{
SqlCommand cmd = new SqlCommand("SELECT QtqSlit,QtyPcs,Design FROM TestOrderStatus where [email protected]");
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@JO", JO);
connection.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
QtqSlit = reader.GetInt32(0);
QtyPcs = reader.GetInt32(1);
Design = reader.GetString(2);
}
}
if (QtqSlit == 0)
{
Message = " user name or password is incorrect";
}
reader.Close();
connection.Close();
}
ReturnOrder rt = new ReturnOrder();
rt.Message = Message;
rt.QtqSlit = QtqSlit;
rt.QtyPcs = QtyPcs;
rt.Design = Design;
return rt;
}
代碼 公共類ReturnOrder { 公共串消息的其餘部分; public int QtqSlit; public int QtyPcs; 公共字符串設計; } –
首先你不需要循環內部。這將讀取三次當前記錄的三個字段。一個就足夠了。第二個while循環,在第一個循環(第一個記錄)之後,再次運行,替換第一個循環中加載的值(如果有3個記錄,它將再次運行,等等)。所以你最後只有一條記錄,最後一條 – Steve