zoukankan      html  css  js  c++  java
  • 【原创】 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);
        }

  • 相关阅读:
    CSS 页面锚点设置
    CSS尺寸 物理像素、CSS像素、dip、dpr、ppi、dpi(一)
    项目代码格式化规范
    Vue 计算属性与监听属性区别
    Python操作InfluxDB
    InfluxDB学习
    Redis学习(五)| 哈希 Hash
    Redis学习(四)| 字符串 String
    Redis学习(三)| 命令、键
    Redis学习(二)| 数据类型
  • 原文地址:https://www.cnblogs.com/cosiray/p/1562988.html
Copyright © 2011-2022 走看看