zoukankan      html  css  js  c++  java
  • 关于IDataReader.GetSchemaTable的一些事情

    http://stackoverflow.com/questions/1574492/how-does-getschematable-work

    The implementation of IDataReader.GetSchemaTable() is up to the provider - so it will vary. You can write your own providers and do it any way you want.

    To be honest this is bad bit of design in the framework - you should never have interface methods that return an untyped DataTable or DataSet as that result could contain anything. Kinda defeats the point of constraining it by an interface in the first place: "you must have a method that returns DataTable but we don't care what rows or columns it has"

    Even if the provider is SQL GetSchemaTable() doesn't go back to the [syscolumns] or [sysobjects]. That would be an additional DB call, require additional privileges and not work anyway, as the result set doesn't need to reflect any objects in the DB.

    I'm not certain, but I'd expect the vast majority of IDataReader.GetSchemaTable() implementations to read some properties of the meta data held with the result set.

    http://axislover.blog.163.com/blog/static/10776515200742792722670/

    public static DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader)
            {
                //把那个DataReader转化成DataTable。
                DataTable datatable = new DataTable();
                DataTable schemaTable = dataReader.GetSchemaTable();
                //动态添加列
                try
                {
                    foreach (DataRow myRow in schemaTable.Rows)
                    {
                        DataColumn myDataColumn = new DataColumn();
                        myDataColumn.DataType = myRow[0].GetType();
                        myDataColumn.ColumnName = myRow[0].ToString();
                        datatable.Columns.Add(myDataColumn);
                    }
                    //添加数据
                    while (dataReader.Read())
                    {
                        DataRow myDataRow = datatable.NewRow();
                        for (int i = 0; i < schemaTable.Rows.Count; i++)
                        {
                            myDataRow[i] = dataReader[i];
                            Type type = dataReader[i].GetType();
                            switch (type.Name)
                            {
                                case "String":
                                    myDataRow[i] = (string)dataReader[i];
                                    break;
                                case "Int16":
                                    myDataRow[i] = (short)dataReader[i];
                                    break;
                                case "Int32":
                                    myDataRow[i] = (int)dataReader[i];
                                    break;
                                case "Int64":
                                    myDataRow[i] = (long)dataReader[i];
                                    break;
                                case "DateTime":
                                    myDataRow[i] = (DateTime)dataReader[i];
                                    break;
                                case "Decimal":
                                    myDataRow[i] = (decimal)dataReader[i];
                                    break;
                                case "Char":
                                    myDataRow[i] = (char)dataReader[i];
                                    break;
                                case "Double":
                                    myDataRow[i] = (double)dataReader[i];
                                    break;
                                default:
                                    myDataRow[i] = dataReader[i];
                                    break;
                            }
                        }
                        datatable.Rows.Add(myDataRow);
                        myDataRow = null;
                    }
                    schemaTable = null;
                    dataReader.Close();
                    return datatable;
                }
                catch (Exception ex)
                {
                    Error.Log(ex.ToString());
                    throw new Exception("转换出错出错!", ex);
                }
            }

    http://www.cnblogs.com/puresoul/archive/2010/06/29/1767333.html

    http://weijingnawjn.blog.163.com/blog/static/3719707720091129101023132/

    http://blog.csdn.net/jianxiong8814/article/details/2221635

  • 相关阅读:
    Centos PHP+Apache执行exec()等Linux脚本权限设置的详细步骤
    新版本的bettercap不好用, 如何安装和编译旧版本的bettercap
    iqiyi__youku__cookie_设置
    window系统命令行设置proxy----Setting a proxy for Windows using the command-line
    修改Electron的libcc(libchromiumcontent)源码,重新编译electron, 设置event.isTrusted为true
    apache配置伪静态Rewrite
    sql注入工具:sqlmap命令
    Reject insecure SameSite=None cookies
    Spring Session Session Max Inactive Interval
    nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
  • 原文地址:https://www.cnblogs.com/s5689412/p/4027955.html
Copyright © 2011-2022 走看看