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);
        }

  • 相关阅读:
    JDBC 连接 MySQL 数据库
    通过java类的反射机制获取类的属性类型
    反射机制实例化类,并获取类中的属性、方法、和构造器
    java8u162反射机制的一个BUG
    Java反射关于getDeclaredMethods()和getMethods()的区别
    Java反射
    30天C#基础巩固------了解委托,string练习
    30天C#基础巩固------读写流(StreamWrite/StreamReader)
    30天C#基础巩固------集合,File(文件操作 ),Encoding处理字符集
    30天C#基础巩固------面向鸭子编程,关于string和File的练习
  • 原文地址:https://www.cnblogs.com/cosiray/p/1562988.html
Copyright © 2011-2022 走看看