Ejemplo n.º 1
0
 /// <summary>
 /// 将数据对象转换成整形
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static int ObjectToInt32(object obj)
 {
     return(DataConvert.CLng(obj));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 查询记录是否存在
 /// </summary>
 /// <param name="strCommand">查询命令</param>
 /// <param name="cmdParams">查询参数</param>
 /// <returns>存在返回true 否则false</returns>
 public static bool Exists(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
 {
     return(DataConvert.CLng(ExecuteScalar(cmdType, cmdText, commandParameters)) > 0);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取表里某字段的最大值
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="fieldName">字段名</param>
        /// <returns>该字段在表里的最大值</returns>
        public static int GetMaxId(string tableName, string fieldName)
        {
            string query = "select max(" + fieldName + ") from " + tableName;

            return(DataConvert.CLng(ExecuteScalar(CommandType.Text, query, null)));
        }
Ejemplo n.º 4
0
        private static SqlParameter GetPara(DataRow dr)
        {
            string       FieldType = dr["FieldType"].ToString();
            SqlParameter result    = new SqlParameter();

            switch (FieldType)
            {
            case "TextType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NVarChar, 255);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "OptionType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NVarChar, 255);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "GradeOptionType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NVarChar, 255);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "ListBoxType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NText);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "DateType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.DateTime);
                result.Value = DataConvert.CDate(dr["FieldValue"].ToString());
                break;

            case "MultipleHtmlType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NText);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "MultipleTextType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NText);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "FileType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NText);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "PicType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NVarChar, 255);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "FileSize":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NVarChar, 255);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "ThumbField":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NVarChar, 255);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "MultiPicType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NText);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "OperatingType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NVarChar, 255);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "SuperLinkType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NVarChar, 255);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "BoolType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.Bit, 1);
                result.Value = dr["FieldValue"].ToString();
                break;

            case "int":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.Int);
                result.Value = DataConvert.CLng(dr["FieldValue"].ToString());
                break;

            case "NumType":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.Float);
                result.Value = DataConvert.CFloat(dr["FieldValue"].ToString());
                break;

            case "float":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.Float);
                result.Value = DataConvert.CFloat(dr["FieldValue"].ToString());
                break;

            case "money":
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.Money);
                result.Value = DataConvert.CFloat(dr["FieldValue"].ToString());
                break;

            default:
                result       = new SqlParameter(dr["FieldName"].ToString(), SqlDbType.NVarChar, 255);
                result.Value = dr["FieldValue"].ToString();
                break;
            }
            return(result);
        }