从Web服务和Xamarin Android中从SQL Server中检索多行



我想从Web服务中的SQL Server检索多行。当我搜索JO数字1时,我会得到2行,而我的表名是TestOrderStatus

当我在搜索结果中仅获得一行时。

感谢所有

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 JO=@JO");
        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;
}

如果您想要多个结果,则需要多个行的列表。因此您的代码可能是这样的。

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(List<ReturnOrder>))]
public List<ReturnOrder> OrderStatus(string JO)  /// get list of notes
{
    List<ReturnOrder> result=new List<ReturnOrder>();
    int QtqSlit = 0;
    int QtyPcs = 0;
    String Design = "";
    string Message = "";
    //try
    //{
        SqlDataReader reader;
        using (SqlConnection connection = new SqlConnection(DBConnection.ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("SELECT QtqSlit,QtyPcs,Design  FROM TestOrderStatus where JO=@JO");
            cmd.CommandType = CommandType.Text;
            cmd.Connection = connection;
            cmd.Parameters.AddWithValue("@JO", JO);
            connection.Open();
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                    QtqSlit = reader.GetInt32(0);
                    QtyPcs = reader.GetInt32(1);
                    Design = reader.GetString(2);
    ReturnOrder rt = new ReturnOrder();
    rt.Message = Message;
    rt.QtqSlit = QtqSlit;
    rt.QtyPcs = QtyPcs;
    rt.Design = Design;
result.add(rt);

            }
            if (QtqSlit == 0)
            {
                Message = " user name or password is in correct";
            }
            reader.Close();
            connection.Close();
        }
    //}
    //catch (Exception ex)
    //{
    //    Message = " cannot access to the data";
    //}


    return result;
}

谢谢您现在的Web服务还可以,但是当他召唤Xamrian Android中的值时,不知道。

公共类MainlistView:活动 { 受保护的替代空隙(捆绑包( { base.oncreate(捆绑(;

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Mainlistview);

        ListView ListView = FindViewById<ListView>(Resource.Id.listView1);

        Selling.WebServiceDB ws = new Selling.WebServiceDB();
        ws.OrderStatusListCompleted += Ws_OrderStatusListCompleted;
        ws.OrderStatusListAsync(Convert.ToString(1));

    }

    private void Ws_OrderStatusListCompleted(object sender, Selling.OrderStatusListCompletedEventArgs e)
    {
        ListView ListView = FindViewById<ListView>(Resource.Id.listView1);
        string msg = "";
         if (e.Result.QtqSlit.ToString().Equals("0"))
        {
            msg = e.Result.Message;
        }
        else
        {
            // full class
            List<TableItem> tableItems = new List<TableItem>();
            tableItems.Add(new TableItem("" + e.Result.QtqSlit, "" + e.Result.QtyPcs, Resource.Drawable.Icon));
            ListView.Adapter = new HomeScreenAdapter(this, tableItems);

        }
    }

相关内容

  • 没有找到相关文章

最新更新