当前位置: 首页>>代码示例>>C#>>正文


C# IDataParameter.SetValue方法代码示例

本文整理汇总了C#中IDataParameter.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# IDataParameter.SetValue方法的具体用法?C# IDataParameter.SetValue怎么用?C# IDataParameter.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDataParameter的用法示例。


在下文中一共展示了IDataParameter.SetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateObj2Table

        public int UpdateObj2Table(object obj, string strTableName, string strWhere)
        {
            string sql = "select * from " + strTableName + " where 1!=1";
            DataSet ds = this.ExecuteDataset(sql);
            Type myType = obj.GetType();
            System.Reflection.PropertyInfo[] pInfos = myType.GetProperties();
            StringBuilder strKey = new StringBuilder();
            int count = 0;
            for (int i = 0; i < pInfos.Length; i++)
            {
                System.Reflection.PropertyInfo pPropertyInfo = pInfos[i];
                if (ds.Tables[0].Columns.Contains(pPropertyInfo.Name))
                {
                    count++;
                }
            }

            IDataParameter[] parameterValues = new IDataParameter[count];
            count = 0;
            for (int i = 0; i < pInfos.Length; i++)
            {
                System.Reflection.PropertyInfo pPropertyInfo = pInfos[i];
                if (ds.Tables[0].Columns.Contains(pPropertyInfo.Name))
                {
                    strKey.Append("," + pPropertyInfo.Name + "=:x" + pPropertyInfo.Name);
                    parameterValues.SetValue(this.GetParameter(":x" + pPropertyInfo.Name, pPropertyInfo.GetValue(obj, null)), count);
                    count++;
                }
            }

            string strSql = "update " + strTableName + " set " + strKey.ToString().Remove(0, 1) + " where " + strWhere;

            return this.ExecuteNonQuery(strSql, parameterValues);
        }
开发者ID:jokingzhou,项目名称:AnJi-DevZoneGIS,代码行数:34,代码来源:AdoHelper.cs

示例2: InsertObj2Table

        public int InsertObj2Table(object obj, string strTableName)
        {
            string sql = "select * from " + strTableName + " where 1!=1";
            DataSet ds = this.ExecuteDataset(sql);

            Type myType = obj.GetType();
            System.Reflection.PropertyInfo[] pInfos = myType.GetProperties();
            StringBuilder strKey = new StringBuilder();
            StringBuilder strValue = new StringBuilder();
            int count = 0;
            for (int i = 0; i < pInfos.Length; i++)
            {
                System.Reflection.PropertyInfo pPropertyInfo = pInfos[i];
                if (ds.Tables[0].Columns.Contains(pPropertyInfo.Name))
                {
                    count++;
                }
            }

            IDataParameter[] parameterValues = new IDataParameter[count];
            count = 0;
            for (int i = 0; i < pInfos.Length; i++)
            {
                System.Reflection.PropertyInfo pPropertyInfo = pInfos[i];
                if (ds.Tables[0].Columns.Contains(pPropertyInfo.Name))
                {
                    strKey.Append("," + pPropertyInfo.Name);
                    strValue.Append(",:x" + pPropertyInfo.Name);
                    string typename = pPropertyInfo.PropertyType.FullName;
                    if (typename == "System.Byte[]")
                    {
                        byte[] bytes = pPropertyInfo.GetValue(obj, null) as byte[];
                        if (bytes == null || bytes.Length == 0)
                        {
                            parameterValues.SetValue(this.GetParameter(":x" + pPropertyInfo.Name, DBNull.Value), count);
                        }
                        else
                        {
                            parameterValues.SetValue(this.GetParameter(":x" + pPropertyInfo.Name, pPropertyInfo.GetValue(obj, null)), count);
                        }
                    }
                    else
                    {
                        parameterValues.SetValue(this.GetParameter(":x" + pPropertyInfo.Name, pPropertyInfo.GetValue(obj, null)), count);
                    }
                    count++;
                }
            }

            string strSql = "insert into " + strTableName + " (" + strKey.ToString().Remove(0, 1) + ") values(" + strValue.ToString().Remove(0, 1) + ")";
            return this.ExecuteNonQuery(strSql, parameterValues);
        }
开发者ID:jokingzhou,项目名称:AnJi-DevZoneGIS,代码行数:52,代码来源:AdoHelper.cs


注:本文中的IDataParameter.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。