【原创】 ASP.NET + C# + WEBSERVICE 返回表数据和记录数据

public static List<string[]> LoadDataTable(string tablename)
    {
        DataTable dt = Admin.GetDataTable("select * from " + tablename + " order by id desc");
        if (dt.Rows.Count > 0)
        {
            List<string[]> list = new List<string[]>();

            DataTable dt_title = Admin.GetTableSchema(tablename);
            if (dt_title.Rows.Count > 0)
            {
                string[] fieldname = new string[dt_title.Rows.Count];
                for (int f = 0; f < dt_title.Rows.Count; f++)
                {
                    fieldname.SetValue(dt_title.Rows[f][2].ToString().Trim(), f);
                }
                list.Add(fieldname);
            }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string[] fieldvalue = new string[dt.Columns.Count];
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    fieldvalue.SetValue(dt.Rows[i][j].ToString().Trim().Replace("00:00:00", "").Replace("0:00:00", ""), j);
                }
                list.Add(fieldvalue);
            }
            return list;
        }
        else
        {
            return null;
        }
    }

    public static List<string[]> LoadDataRow(string tablename, string id)
    {
        if (WService.Check())
        {
            DataRow dr = Admin.GetDataRow("select * from " + tablename + " where id = " + id);
            if (dr != null)
            {
                List<string[]> list = new List<string[]>();
                for (int i = 0; i < dr.Table.Columns.Count; i++)
                {
                    string[] str = { dr.Table.Columns[i].ColumnName, dr[i].ToString().Trim().Replace("00:00:00", "").Replace("0:00:00", "") };
                    list.Add(str);
                }
                return list;
            }
            else
            {
                return null;
            }
        }
        else
        {
            //List<string[]> list = new List<string[]>();
            //string[] nopower = { "没有登录或登录超时,请重新登录!" };
            //list.Add(nopower);
            //return list;
            return null;
        }
    }

    [WebMethod]
    public List<string[]> LoadTable_Yuekan(string id)
    {
        return LoadDataTable("yuekan");
    }

    [WebMethod]
    public List<string[]> LoadRow_Yuekan(string id)
    {
        return LoadDataRow("yuekan", id);
    }

原文地址:https://www.cnblogs.com/cosiray/p/1562988.html