【原创】 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);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值