一份礼物: 自动填充SqlCommand.Parameters的类(2)

command

/// <summary>
        /// 获取存储过程的相关表的列名和isnuable
        /// </summary>
        /// <param name="spid">存储过程名称</param>
        /// <returns>Hastable</returns>
        public Hashtable SPDependonTable(Int32 spid)
        {            
            try
            {
                //验证连接
                if(conn!=null && conn.State!=ConnectionState.Open)
                {
                    conn.Open();
                }
                else
                {
                    conn= new SqlConnection(this.connectionString);
                    conn.Open();
                }
                string sqlstr="SELECT name, isnullable as allowNUll FROM dbo.syscolumns WHERE (id IN (SELECT DISTINCT id FROM dbo.sysobjects WHERE (id IN (SELECT DISTINCT dbo.sysdepends.depid FROM dbo.sysdepends WHERE (dbo.sysdepends.id ="+spid+")))))";
                //获取相关表的isnullable
                SqlDataAdapter comm= new SqlDataAdapter(sqlstr,conn );
                DataSet depds=new DataSet();
                comm.Fill(depds,"dbo.syscolumns");
                Hashtable dependtbl=new Hashtable();
                //建立Hashtble
                for(int n=0;n<depds.Tables[0].Rows.Count;n++)
                {
                    string keyname="@"+depds.Tables["dbo.syscolumns"].Rows[n]["name"];
                    Boolean isnullabled=Convert.ToBoolean( depds.Tables["dbo.syscolumns"].Rows[n]["allowNull"]);
                    dependtbl.Add(keyname,isnullabled);
                }
                
                return dependtbl;
            }
            catch(SqlException se)
            {
                throw(se);
            }
            catch(Exception e)
            {
                throw(e);
            }
            finally
            {
                if(conn.State ==ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
        /// <summary>
        /// 获得指定表的所有字段对象
        /// </summary>
        /// <param name="TableName">表名</param>
        /// <returns>System.Data.DataTable</returns>
        public DataTable GetFields(String TableName)
        {
            try
            {                
                DataSet myDataSet=new DataSet();
                //验证连接
                if(conn!=null && conn.State!=ConnectionState.Closed)
                {
                    conn.Open();
                }
                else
                {
                    conn= new SqlConnection(this.connectionString);
                    conn.Open();
                }
                SqlDataAdapter comm= new SqlDataAdapter("SELECT * from "+TableName,conn);
            
                comm.FillSchema(myDataSet, SchemaType.Mapped,TableName);
                        
                return myDataSet.Tables[0];
            }
            catch(SqlException se)
            {
                throw(se);
            }
        }
        /// <summary>
        ///私有: 获取数据类型(DbType)
        /// </summary>
        /// <param name="typename">数据类型名称</param>
        /// <returns>DbType</returns>
        private DbType getDbType(string typename)
        {
            //DbType t;
            #region switch datatype
            switch(typename)
            {
                    //int64
                case "bigint":                    
                    return DbType.Int64;
                    //break;
                    //int32
                case "int":                
                    return DbType.Int32;
                    //break;
                    //int16                        
                case "smallint":                    
                    return DbType.Int16;
                    //break;
                    //byte
                case "binary":
                    return DbType.Byte;
                    //break;
                case "image":                    
                    return DbType.Byte;
                    //break;
                case "varbinary":                                        
                    return DbType.Byte;
                    //break;
                case "tinyint":
                    return DbType.Byte;
                    //break;
                    //boolean
                case "bit":
                    return DbType.Boolean;
                    //break;
                    //string
                case "varchar":
                    return DbType.String;
                    //break;
                case "text":
                    return DbType.String;
                    //break;
                case "nvarchar":
                    return DbType.String;
                    //break;
                case "ntext":
                    return DbType.String;
                    //break;
                case "nchar":
                    return DbType.String;
                    //break;
                case "char":
                    return DbType.String ;
                    //break;
                    //DateTime
                case "datetime":
                    return DbType.DateTime;
                    //break;
                case "smalldatetime":
                    return DbType.DateTime;
                    //break;
                case "timestamp":
                    return DbType.DateTime;
                    //break;
                    //double
                case "Float":
                    return DbType.Double;
                    //break;
                    //decimal
                case "decimal":
                    return DbType.Decimal;
                    //break;                    
                case "money":
                    return DbType.Decimal ;
                    //break;
                case "smallmoney":
                    return DbType.Decimal;
                    //break;                    
                default:
                    return DbType.Object;
                    //break;
            }
                        #endregion
            
        }
        /// <summary>
        /// 获取数据类型(SqlDbType)
        /// </summary>
        /// <param name="typename">数据类型名称</param>
        /// <returns>SqlDbType</returns>
        public SqlDbType getSqlDbType(string typename)
        {
            //SqlDbType t;
            #region switch datatype
            switch(typename)
            {
                    //int64
                case "bigint":
                    return SqlDbType.BigInt;
                    //break;
                    //int32
                case "int":
                    return SqlDbType.Int;
                    //break;
                    //int16                        
                case "smallint":
                    return SqlDbType.SmallInt;
                    //break;
                    //byte
                case "binary":
                    return SqlDbType.Binary;
                    //break;
                case "image":
                    return SqlDbType.Image;
                    //break;
                case "varbinary":                    
                    return SqlDbType.VarBinary;
                    //break;
                case "tinyint":
                    return SqlDbType.TinyInt;
                    //break;
                    //boolean
                case "bit":
                    return SqlDbType.Bit;
                    //break;
                    //string
                case "varchar":
                    return SqlDbType.VarChar;
                    //break;
                case "text":
                    return SqlDbType.Text;
                    //break;
                case "nvarchar":
                    return SqlDbType.NVarChar;                    
                    //break;
                case "ntext":
                    return SqlDbType.NText ;                    
                    //break;
                case "nchar":
                    return SqlDbType.NChar;                    
                    //break;
                case "char":
                    return SqlDbType.Char;                    
                    //break;
                    //DateTime
                case "datetime":
                    return SqlDbType.DateTime;                     
                    //break;
                case "smalldatetime":
                    return SqlDbType.SmallDateTime;                     
                    //break;
                case "timestamp":
                    return SqlDbType.Timestamp;                     
                    //break;
                    //double
                case "Float":
                    return SqlDbType.Float;
                    //break;
                    //decimal
                case "decimal":
                    return SqlDbType.Decimal;                    
                    //break;                    
                case "money":
                    return SqlDbType.Money;                    
                    //break;
                case "smallmoney":
                    return SqlDbType.SmallMoney;                     
                    //break;                    
                default:
                    return SqlDbType.Variant;                    
                    //break;
            }
                        #endregion
            
        }
        #endregion
    }
}

时间: 2024-09-10 07:48:08

一份礼物: 自动填充SqlCommand.Parameters的类(2)的相关文章

一份礼物: 自动填充SqlCommand.Parameters的类(1)

command //---------------------------------------------------//日期: 2002.1.10//作者: raxzhang//版权: raxzhang//环境: Microsoft Visual Studio.Net 7.0//语言: Visual C#//类型: 类文件,编译后为.dll文件//描述: 这是作为对数据操作的最常用的属性和方法类.//       是一个基础类.可以被继承和扩展.//注意: 使用这个类的条件是-1.dbo用

PS+SKETCH提高效率的自动填充神器插件CRAFT

  如果你使用Photoshop和Sketch做界面设计时,肯定会碰到一个问题,那就是需要填充很多真实的图片到界面里.这个过程非常浪费时间,有没有能节省时间的办法呢?当然是有的,那就是Craft. 下载地址: Craft官网(输入邮箱,点击"get it free"):http://labs.invisionapp.com 网盘链接:http://pan.baidu.com/s/1eQPDSS6 Craft有什么牛逼的功能? 因为米田用的Sketch为主,所以内容也是以此为主.Phot

浏览器自动填充存漏洞,可能泄露你的个人隐私

当你在注册新账号,或者填写收货地址时,大堆信息是否让你头疼?所幸的是,大多数浏览器都自带了的自动填充表单的功能,一秒钟就能帮你填好所有的所有输入框. 可是,最近一个芬兰的网页开发者和黑客 Viljami Kuosmanen 发现了一个自动填写表单功能重大的潜在安全漏洞,他表示诸如 Chrome.Safari 和 Opera 等浏览器,或是 LastPass 这样带自动填充功能的浏览器插件,都可能会泄露用户的隐私. 自动填表如何泄露你的隐私 一般来说,在使用自动填充功能之前,用户需要提前把需要自动

360极速浏览器管理“自动填充”条目

您可以使用"自动填充选项"对话框添加.编辑或删除已创建的"自动填充"条目. 点击地址栏后的"工具"按钮,然后选择"选项" 在"个人资料"标签找到"自动填充选项"按钮,并点击. 在显示的对话框中,您可以根据需要创建任意数量的个人资料. 如果您要删除已保存的表单,请使用"清除浏览数据"对话框.

Java中ResultSet数据自动填充到类中&amp;amp;类实例填充PreparedStatement

需求: (1)提取ResultSet中值到一个类中挺麻烦的,需要new一个变量,使用对应成员的Set方法赋值,能不能根据类的Class,直接提取出ResultSet中的数据,最后返回实例化的类? (2)可以用PreparedStatement预编译带变量的sql语句,在execute之前需要将变量值填充进去,一个一个设置太麻烦了,能不能提供一个类变量,使用类成员变量的值自动填充PreparedStatement? 这样的功能许多开源的框架可以实现,但是不想因为这么一点点的需求去学习那么庞大的一套

WPS 2009自动填充规则技巧总结

1.默认填充规则:WPS对"数字"默认以序列方式填充:对"文本+数字"组合,文本默认复制填充,数字默认以序列方式填充. 2.自动填充中<CTRL>键的作用:在按住<CTRL>键同时拖曳单元格,则不论是"数字"还是"文本+数字"组合,则一律以复制方式进行填充. 3.右键填充:可以用右键拖曳单元格填充,而后在右键快捷菜单中选择填充方式,甚至可以转到"序列"对话框进行更为详细的设置.

Joyo搜索框是如何完成中文自动填充的

今天跑到Joyo网去看看我需要的书到货没有,顺便搜索了一下其他书籍,我发现有自动填充,原来没有发现呢.汗颜. 案例: 如果我输入de,下面会有"德语","德川家康"等条目出现,伴随有多个搜索结果. 问题: Joyo是怎么实现的呢? 分析: 当然我不可能看到其源代码和数据库schema.下面按照我自己的思路来解决这个问题. 首先看看Joyo网的效果: 当你输入"de",会出现以下结果: 我们可以看到会出现以"de"发音的汉字,当

ASP.NET中实现Form表单字段值自动填充到操作模型中

  这篇文章主要介绍了ASP.NET中实现Form表单字段值自动填充到操作模型中,本文模仿MVC模式中的自动映射表单了模型,使用泛型和反射实现,需要的朋友可以参考下 我们知道ASP.NET MVC有个强大的地方就是Form表单提交到action的时候,可以直接将Form的参数直接装配到action的参数实体对象中 比如 代码如下: action方法 Register(UserModel userModel) { ............................. } 在提交表单的时候,会

WPS 2009自动填充规则技巧

   1.默认填充规则:WPS对"数字"默认以序列方式填充:对"文本+数字"组合,文本默认复制填充,数字默认以序列方式填充.     2.自动填充中<CTRL>键的作用:在按住<CTRL>键同时拖曳单元格,则不论是"数字"还是"文本+数字"组合,则一律以复制方式进行填充.     3.右键填充:可以用右键拖曳单元格填充,而后在右键快捷菜单中选择填充方式,甚至可以转到"序列"对话框进行