コード例 #1
0
        /**/
        /// <summary>
        /// 执行带一个存储过程参数的的SQL语句。
        /// </summary>
        /// <param name="SQLString">SQL语句</param>
        /// <param name="content">参数内容,比如一个字段是格式复杂的文章,有特殊符号,可以通过这个方式添加</param>
        /// <returns>影响的记录数</returns>
        public int ExecuteSql(string SqlString, string content)
        {
            using (System.Data.IDbConnection iConn = this.GetConnection())
            {
                using (System.Data.IDbCommand iCmd = GetCommand(SqlString, iConn))
                {
                    System.Data.IDataParameter myParameter = this.iDbPara("@content", "Text");
                    myParameter.Value = content;
                    iCmd.Parameters.Add(myParameter);
                    iConn.Open();
                    try
                    {
                        int rows = iCmd.ExecuteNonQuery();
                        return(rows);
                    }
                    catch (System.Exception e)
                    {
                        throw new Exception(e.Message);
                    }
                    finally
                    {
                        if (iConn.State != ConnectionState.Closed)
                        {
                            iConn.Close();
                        }
                    }
                }
            }
        }

        /**/
        /// <summary>
        /// 向数据库里插入图像格式的字段(和上面情况类似的另一种实例)
        /// </summary>
        /// <param name="strSQL">SQL语句</param>
        /// <param name="fs">图像字节,数据库的字段类型为image的情况</param>
        /// <returns>影响的记录数</returns>
        public int ExecuteSqlInsertImg(string SqlString, byte[] fs)
        {
            using (System.Data.IDbConnection iConn = this.GetConnection())
            {
                using (System.Data.IDbCommand iCmd = GetCommand(SqlString, iConn))
                {
                    System.Data.IDataParameter myParameter = this.iDbPara("@content", "Image");
                    myParameter.Value = fs;
                    iCmd.Parameters.Add(myParameter);
                    iConn.Open();
                    try
                    {
                        int rows = iCmd.ExecuteNonQuery();
                        return(rows);
                    }
                    catch (System.Exception e)
                    {
                        throw new Exception(e.Message);
                    }
                    finally
                    {
                        if (iConn.State != ConnectionState.Closed)
                        {
                            iConn.Close();
                        }
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// 以事务方式执行拼接好的sql语句组
 /// </summary>
 public static void RunSqlStatement()
 {
     BaseSQL.ExecuteSqlTran(strSqlLlist);
     IDataParameter[] parameters = new System.Data.IDataParameter[1];  //实例化参数对象
     parameters[0] = new SqlParameter("@returnMessage", string.Empty); //参数对象赋值
     BaseSQL.RunProcedure("FrmRight_RefreshButtonInfo", parameters);   //执行存储过程,刷新button相关表
 }
コード例 #3
0
        /**/
        /// <summary>
        /// 执行一条计算查询结果语句,返回查询结果(object)。
        /// </summary>
        /// <param name="SQLString">计算查询结果语句</param>
        /// <returns>查询结果(object)</returns>
        public object GetSingle(string SqlString)
        {
            using (System.Data.IDbConnection iConn = GetConnection())
            {
                using (System.Data.IDbCommand iCmd = GetCommand(SqlString, iConn))
                {
                    iConn.Open();
                    try
                    {
                        object obj = iCmd.ExecuteScalar();
                        if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
                        {
                            return(null);
                        }
                        else
                        {
                            return(obj);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        LogHelper.WriteLog(ex, SqlString);
                        return(-1);
                    }
                    finally
                    {
                        if (iConn.State != ConnectionState.Closed)
                        {
                            iConn.Close();
                        }
                    }
                }
            }
        }

        /**/
        /// <summary>
        /// 执行带一个存储过程参数的的SQL语句。
        /// </summary>
        /// <param name="SQLString">SQL语句</param>
        /// <param name="content">参数内容,比如一个字段是格式复杂的文章,有特殊符号,可以通过这个方式添加</param>
        /// <returns>影响的记录数</returns>
        public int ExecuteSql(string SqlString, string content)
        {
            using (System.Data.IDbConnection iConn = this.GetConnection())
            {
                using (System.Data.IDbCommand iCmd = GetCommand(SqlString, iConn))
                {
                    System.Data.IDataParameter myParameter = this.iDbPara("@content", "Text");
                    myParameter.Value = content;
                    iCmd.Parameters.Add(myParameter);
                    iConn.Open();
                    try
                    {
                        int rows = iCmd.ExecuteNonQuery();
                        return(rows);
                    }
                    catch (System.Exception ex)
                    {
                        LogHelper.WriteLog(ex, SqlString);
                        return(-1);
                    }
                    finally
                    {
                        if (iConn.State != ConnectionState.Closed)
                        {
                            iConn.Close();
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: FrmAddRemarksBLL.cs プロジェクト: comborep/PSAP
        public static void SaveRemarks(ListView lv, string remarks)
        {
            int newRemarksID;

            IDataParameter[] parameters = new System.Data.IDataParameter[4];  //实例化参数对象
            parameters[0]           = new SqlParameter("@Remarks", remarks);  //参数对象赋值
            parameters[1]           = new SqlParameter("@Founder", "songxi"); //需改成变量change
            parameters[2]           = new SqlParameter("@newRemarksID", SqlDbType.Int);
            parameters[3]           = new SqlParameter("@returnMessage", string.Empty);
            parameters[2].Direction = ParameterDirection.Output;
            parameters[3].Direction = ParameterDirection.Output;
            BaseSQL.RunProcedure("GetNewRemarksID", parameters);
            newRemarksID = Convert.ToInt32(parameters[2].Value);//

            FrmAddRemarksDAO.sqlLlist.Clear();
            foreach (ListViewItem lvi in lv.SelectedItems)
            {
                //项目或文档ID
                int itemID = Convert.ToInt32(lvi.Tag);
                try
                {
                    //如果是文件夹
                    if (lvi.SubItems[4].Text == "folder")
                    {
                        //获得项目列表
                        DataTable dt = FrmProjectDocumentDAO.GetAllLevelProjects(itemID);
                        //项目下的所有项目
                        foreach (DataRow dr in dt.Rows)
                        {
                            //调用保存【项目备注】方法
                            FrmAddRemarksDAO.SaveProjectsRemarks_AddSql(Convert.ToInt32(dr["projectID"]), newRemarksID);
                        }

                        //获得文件列表
                        dt = FrmProjectDocumentDAO.GetAllLevelDocuments(itemID);
                        //项目下的所有文件
                        foreach (DataRow dr in dt.Rows)
                        {
                            //调用保存【文档备注】方法
                            FrmAddRemarksDAO.SaveDocumentsRemarks_AddSql(Convert.ToInt32(dr["documentID"]), newRemarksID);
                        }
                    }
                    else//如果是文件
                    {
                        DataRow dr;
                        dr = FrmProjectDocumentDAO.GetDocumentInfo(itemID);
                        //调用保存【文档备注】方法
                        FrmAddRemarksDAO.SaveDocumentsRemarks_AddSql(Convert.ToInt32(dr["documentID"]), newRemarksID);
                    }
                    BaseSQL.ExecuteSqlTran(FrmAddRemarksDAO.sqlLlist);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 更新生产计划单BOM信息
        /// </summary>
        public bool Update_ProductionScheduleBom(SqlCommand cmd, string psNoStr, out string errorText)
        {
            int          resultInt = 0;
            SqlParameter p1        = new SqlParameter("@PsNo", SqlDbType.VarChar);

            p1.Value = psNoStr;
            IDataParameter[] parameters = new System.Data.IDataParameter[] { p1 };
            return(BaseSQL.RunProcedure(cmd, "P_Update_ProductionScheduleBom", parameters, out resultInt, out errorText));
        }
コード例 #6
0
ファイル: DataBaseAccess.cs プロジェクト: ccjchina/DBHelper-1
        /// <summary>
        /// 使用离线数据库连接器,无需使用Open方法,添加存储过程参数
        /// </summary>
        /// <param name="ParameterName">参数名</param>
        /// <param name="ParameterValue">参数值</param>
        /// <param name="DbType">对象类型</param>
        /// <param name="Direction">参数类型</param>
        public void AddProcedureParameterOffline(string ParameterName, object ParameterValue, System.Data.DbType DbType, System.Data.ParameterDirection Direction)
        {
            System.Data.IDataParameter p = this.CommandOffline.CreateParameter();
            p.ParameterName = ParameterName;
            p.Value         = ParameterValue;
            p.DbType        = DbType;
            p.Direction     = Direction;

            this.CommandOffline.Parameters.Add(p);
        }
コード例 #7
0
        /// <summary>
        /// 更新当前的库存数
        /// </summary>
        public bool Update_WarehouseNowInfo(SqlCommand cmd, string warehouseNoStr, int HandleType, out string errorText)
        {
            int          resultInt = 0;
            SqlParameter p1        = new SqlParameter("@WarehouseNo", SqlDbType.VarChar);

            p1.Value = warehouseNoStr;
            SqlParameter p2 = new SqlParameter("@HandleType", SqlDbType.VarChar);

            p2.Value = HandleType;
            IDataParameter[] parameters = new System.Data.IDataParameter[] { p1, p2 };
            return(BaseSQL.RunProcedure(cmd, "P_Update_WarehouseNowInfo", parameters, out resultInt, out errorText));
        }
コード例 #8
0
 public void SetParameter(System.Data.IDataParameter dataParameter, object parameterValue, string dbType)
 {
     if (parameterValue == null)
     {
         dataParameter.Value  = DBNull.Value;
         dataParameter.DbType = DbType.Binary;
     }
     else
     {
         DbGeography geo = (DbGeography)parameterValue;
         //var sqlDbGeography = SqlGeography.Parse(geo.AsText());
         //dataParameter.Value = sqlDbGeography.Serialize().Value;
     }
 }
コード例 #9
0
        public override void Save()
        {
            BeginTransaction();

            System.Data.SqlClient.SqlCommand sqluser = new System.Data.SqlClient.SqlCommand();

            if (this.ID != 0)
            {
                sqluser.CommandText = "Update users set username=@, pass=@, email=@, location=@, user_type=@ where id_user=@";
            }/*
              * else
              * {
              * sqluser.CommandText = "insert into users(username, pass, email, location, type) values (@, @, @, @, @)";
              * }*/

            sqluser.Transaction = CurrentTransaction;
            System.Data.IDataParameter p = sqluser.Parameters.Add("@usrn", SqlDbType.Int);
            p.Value = _username;

            p       = sqluser.Parameters.Add("@pas", SqlDbType.VarChar);
            p.Value = _password;

            p       = sqluser.Parameters.Add("@em", SqlDbType.VarChar);
            p.Value = _email;

            p       = sqluser.Parameters.Add("@lo", SqlDbType.VarChar);
            p.Value = _location;

            p       = sqluser.Parameters.Add("@ty", SqlDbType.VarChar);
            p.Value = _user_type;

            /*if (this.ID != 0)
             * {*/
            p       = sqluser.Parameters.Add("@id", SqlDbType.Int);
            p.Value = this.ID;
            /* } */

            int id = ExecuteTransactedNonQuery(sqluser);

            /*if (this.ID == 0)
             * {
             *  this.myID = id;
             * }*/

            CommitTransaction();
        }
コード例 #10
0
ファイル: ParametersHelper.cs プロジェクト: xxdoc/SKS
 /// <summary>
 /// Extracts the command information from the command object and add specific information based on the factory being use.
 /// </summary>
 /// <param name="theCommand">Command to be processed.</param>
 /// <param name="factory">The factory to be use.</param>
 public static void DeriveParameters(DbCommand theCommand, DbProviderFactory factory)
 {
     theCommand.Parameters.Clear();
     if (theCommand.CommandType == CommandType.StoredProcedure)
     {
         using (DbConnection conn = factory.CreateConnection())
         {
             conn.ConnectionString = theCommand.Connection.ConnectionString;
             conn.Open();
             using (DbCommand pivotCommand = factory.CreateCommand())
             {
                 pivotCommand.CommandText = theCommand.CommandText;
                 pivotCommand.CommandType = theCommand.CommandType;
                 pivotCommand.Connection  = conn;
                 if (theCommand is System.Data.OleDb.OleDbCommand)
                 {
                     if (conn.ConnectionString.Contains("Provider=Microsoft.Jet"))
                     {
                         DeriveParametersFromProcedureCode(conn, pivotCommand);
                     }
                     else
                     {
                         System.Data.OleDb.OleDbCommandBuilder.DeriveParameters((System.Data.OleDb.OleDbCommand)pivotCommand);
                     }
                 }
                 else if (theCommand is System.Data.SqlClient.SqlCommand)
                 {
                     System.Data.SqlClient.SqlCommandBuilder.DeriveParameters((System.Data.SqlClient.SqlCommand)pivotCommand);
                 }
                 else if (theCommand is System.Data.OracleClient.OracleCommand)
                 {
                     System.Data.OracleClient.OracleCommandBuilder.DeriveParameters((System.Data.OracleClient.OracleCommand)pivotCommand);
                 }
                 foreach (DbParameter parameter in pivotCommand.Parameters)
                 {
                     System.Data.IDataParameter cloneParameter = (System.Data.IDataParameter)((ICloneable)parameter).Clone();
                     theCommand.Parameters.Add(cloneParameter);
                 }
             }
         }
     }
 }
コード例 #11
0
ファイル: LocationService.cs プロジェクト: jiyeon037/.NET
        public DataSet GetLocationData(int locationNo)
        {
            System.Data.IDbCommand sqlSelectCommand = EnterpriseManager.DbFactory.CreateDbCommand();
            sqlSelectCommand.CommandText =
                @"
select a.LocationNo, a.LocationName, a.BusinessClassCode, b.CompanyName 
from location a inner join BusinessClass b 
on a.BusinessClassCode = b.BusinessClassCode where a.LocationNo = @locationNo
";
            sqlSelectCommand.CommandType = System.Data.CommandType.Text;

            System.Data.IDataParameter locationNoParam = EnterpriseManager.DbFactory.CreateDataParameter("@locationNo", typeof(int));
            locationNoParam.Value = locationNo;
            sqlSelectCommand.Parameters.Add(locationNoParam);

            // 명령문을 호출한다
            DataSet dataSet = (DataSet)GetDataSet(sqlSelectCommand);

            sqlSelectCommand.Dispose();
            return(dataSet);
        }
コード例 #12
0
ファイル: FrmProjectDocumentDAO.cs プロジェクト: RD-IT/RDPSAP
 /// <summary>
 /// 在服务器创建文件夹
 /// </summary>
 /// <param name="projectName"></param>
 /// <param name="projectPath"></param>
 /// <param name="parentProjectID"></param>
 public static int CreateFolderToSever(string projectName, string projectPath, int parentProjectID)
 {
     //string sql;
     try
     {
         IDataParameter[] parameters = new System.Data.IDataParameter[5];         //实例化参数对象
         parameters[0]           = new SqlParameter("@projectName", projectName); //参数对象赋值
         parameters[1]           = new SqlParameter("@projectPath", projectPath);
         parameters[2]           = new SqlParameter("@parentProjectID", parentProjectID);
         parameters[3]           = new SqlParameter("@newProjectId", SqlDbType.Int);
         parameters[4]           = new SqlParameter("@returnMessage", string.Empty);
         parameters[3].Direction = ParameterDirection.Output;
         parameters[4].Direction = ParameterDirection.Output;
         BaseSQL.RunProcedure("CreateFolderToSever", parameters);
         return(Convert.ToInt32(parameters[3].Value));
     }
     catch (Exception ex)
     {
         ExceptionHandler.HandleException("在服务器创建文件夹错误。", ex);
         return(-1);
     }
 }
コード例 #13
0
 /// <summary>
 /// 在服务器创建文件夹
 /// </summary>
 /// <param name="projectName"></param>
 /// <param name="projectPath"></param>
 /// <param name="parentProjectID"></param>
 public static int CreateFolderToSever(string projectName, string projectPath, int parentProjectID)
 {
     //string sql;
     try
     {
         IDataParameter[] parameters = new System.Data.IDataParameter[5];         //实例化参数对象
         parameters[0]           = new SqlParameter("@projectName", projectName); //参数对象赋值
         parameters[1]           = new SqlParameter("@projectPath", projectPath);
         parameters[2]           = new SqlParameter("@parentProjectID", parentProjectID);
         parameters[3]           = new SqlParameter("@newProjectId", SqlDbType.Int);
         parameters[4]           = new SqlParameter("@returnMessage", string.Empty);
         parameters[3].Direction = ParameterDirection.Output;
         parameters[4].Direction = ParameterDirection.Output;
         BaseSQL.RunProcedure("CreateFolderToSever", parameters);
         return(Convert.ToInt32(parameters[3].Value));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, f.tsmiTs.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(-1);
     }
 }
コード例 #14
0
ファイル: CustomerService.cs プロジェクト: jiyeon037/.NET
        public DataSet GetCustomerData(string CustomerCode)
        {
            System.Data.IDbCommand sqlSelectCommand = EnterpriseManager.DbFactory.CreateDbCommand();

            // Sql Command 명령문
            sqlSelectCommand.CommandText =
                @"select President, Address, BusinessType, BusinessItem from customers where customercode = @customerCode";

            sqlSelectCommand.CommandType = System.Data.CommandType.Text;
            //

            System.Data.IDataParameter CustomerCodeParam = EnterpriseManager.DbFactory.CreateDataParameter("@customerCode", typeof(string));
            CustomerCodeParam.Value = CustomerCode;
            sqlSelectCommand.Parameters.Add(CustomerCodeParam);

            //
            // 명령문을 호출한다
            DataSet dataset = this.GetDataSet(sqlSelectCommand);

            sqlSelectCommand.Dispose();
            return(dataset);
        }
コード例 #15
0
ファイル: LocationService.cs プロジェクト: jiyeon037/.NET
        public LocationSet GetForLocationType(int locationType)
        {
            // Sql Command 명령문
            System.Data.IDbCommand sqlSelectCommand = EnterpriseManager.DbFactory.CreateDbCommand();
            sqlSelectCommand.CommandText =
                @"SELECT * FROM Location 
WHERE LocationType = @locationType
  order by LocationName";
            sqlSelectCommand.CommandType = System.Data.CommandType.Text;
            //
            // 파라미터2값을 만든다
            System.Data.IDataParameter locationTypeParam = EnterpriseManager.DbFactory.CreateDataParameter("@locationType", typeof(int));
            locationTypeParam.Value = locationType;
            sqlSelectCommand.Parameters.Add(locationTypeParam);

            //
            //
            // 명령문을 호출한다
            LocationSet entitySet = ((LocationSet)(this.GetEntitySet(sqlSelectCommand, typeof(LocationSet))));

            sqlSelectCommand.Dispose();
            return(entitySet);
        }
コード例 #16
0
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="strQuerySqlId">查询ID</param>
        /// <param name="strControlTmp">控件列表变量</param>
        /// <returns></returns>
        public static DataSet ExecUserProcedure(string strQuerySqlId, string[,] strControlTmp)
        {
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            dt = GetUserQueryInfo(strQuerySqlId);
            if (!string.IsNullOrEmpty(dt.Rows[0].ItemArray[6].ToString().Trim()))
            {
                int intRowCount             = dt.Rows.Count;
                IDataParameter[] parameters = new System.Data.IDataParameter[intRowCount];//实例化参数对象
                for (int i = 0; i < intRowCount; i++)
                {
                    //string reval = string.Empty;
                    string strParaName = dt.Rows[i].ItemArray[6].ToString();
                    switch (strControlTmp[i, 2].ToLower())
                    {
                    case "int":
                        //reval = "Int32";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Int);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToInt32(strControlTmp[i, 1]);
                        break;

                    case "text":
                        //reval = "String";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Text);//参数对象赋值
                        parameters[i].Value = Convert.ToString(strControlTmp[i, 1]);
                        break;

                    case "bigint":
                        //reval = "Int64";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.BigInt);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToInt64(strControlTmp[i, 1]);
                        break;

                    case "binary":
                        //reval = "System.Byte[]";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Binary);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToByte(strControlTmp[i, 1]);
                        break;

                    case "bit":
                        //reval = "Boolean";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Bit);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToBoolean(strControlTmp[i, 1]);
                        break;

                    case "char":
                        //reval = "String";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Char);//参数对象赋值
                        parameters[i].Value = Convert.ToString(strControlTmp[i, 1]);
                        break;

                    case "datetime":
                        //reval = "System.DateTime";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.DateTime);//参数对象赋值
                        parameters[i].Value = Convert.ToDateTime(strControlTmp[i, 1]);
                        break;

                    case "decimal":
                        //reval = "System.Decimal";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Decimal);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToDecimal(strControlTmp[i, 1]);
                        break;

                    case "float":
                        //reval = "System.Double";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Float);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToDouble(strControlTmp[i, 1]);
                        break;

                    case "image":
                        //reval = "System.Byte[]";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Image);//参数对象赋值
                        parameters[i].Value = Convert.ToByte(strControlTmp[i, 1]);
                        break;

                    case "money":
                        //reval = "System.Decimal";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Money);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToDecimal(strControlTmp[i, 1]);
                        break;

                    case "nchar":
                        //reval = "String";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.NChar);//参数对象赋值
                        parameters[i].Value = Convert.ToString(strControlTmp[i, 1]);
                        break;

                    case "ntext":
                        //reval = "String";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.NText);//参数对象赋值
                        parameters[i].Value = Convert.ToString(strControlTmp[i, 1]);
                        break;

                    case "numeric":
                        //reval = "System.Decimal";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Decimal);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToDecimal(strControlTmp[i, 1]);
                        break;

                    case "nvarchar":
                        //reval = "String";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.NVarChar);//参数对象赋值
                        parameters[i].Value = Convert.ToString(strControlTmp[i, 1]);
                        break;

                    case "real":
                        //reval = "System.Single";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Real);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToSingle(strControlTmp[i, 1]);
                        break;

                    case "smalldatetime":
                        //reval = "System.DateTime";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.SmallDateTime);//参数对象赋值
                        parameters[i].Value = Convert.ToDateTime(strControlTmp[i, 1]);
                        break;

                    case "smallint":
                        //reval = "Int16";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.SmallInt);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToInt16(strControlTmp[i, 1]);
                        break;

                    case "smallmoney":
                        //reval = "System.Decimal";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.SmallMoney);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToDecimal(strControlTmp[i, 1]);
                        break;

                    case "timestamp":
                        //reval = "System.DateTime";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Timestamp);//参数对象赋值
                        parameters[i].Value = Convert.ToDateTime(strControlTmp[i, 1]);
                        break;

                    case "tinyint":
                        //reval = "System.Byte";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.TinyInt);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToByte(strControlTmp[i, 1]);
                        break;

                    case "varbinary":
                        //reval = "System.Byte[]";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.VarBinary);//参数对象赋值
                        parameters[i].Value = string.IsNullOrEmpty(strControlTmp[i, 1]) ? null : (object)Convert.ToByte(strControlTmp[i, 1]);
                        break;

                    case "varchar":
                        //reval = "String";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.VarChar);//参数对象赋值
                        parameters[i].Value = Convert.ToString(strControlTmp[i, 1]);
                        break;

                    case "Variant":
                        //reval = "Object";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.Variant);//参数对象赋值
                        parameters[i].Value = (object)(strControlTmp[i, 1]);
                        break;

                    default:
                        //reval = "String";
                        parameters[i]       = new SqlParameter(strParaName, SqlDbType.VarChar);//参数对象赋值
                        parameters[i].Value = Convert.ToString(strControlTmp[i, 1]);
                        break;
                    }
                }
                ds = BaseSQL.RunProcedure(Convert.ToString(dt.Rows[0].ItemArray[3]).Trim(), parameters, "dd");//执行存储过程
                return(ds);
            }
            return(null);
        }
コード例 #17
0
        public void cc()
        {
            String connectionString = "Data Source=.;Initial Catalog=MyDB;User Id=sa;Password=sa;";
            String dataBaseType     = "SQLServer";

            Draco.DB.QuickDataBase.Configuration.ConnectionInfo connInfo = new ConnectionInfo(connectionString, dataBaseType);

            Draco.DB.QuickDataBase.IDataBaseContext ctx     = new Draco.DB.QuickDataBase.DataBaseContext(connInfo);
            Draco.DB.QuickDataBase.IDataBaseHandler handler = ctx.Handler;
            //开始数据库操作
            //......

            //以IDataBaseHandler对象获取Draco.DB.QuickDataBase.IDataBaseContext对象
            Draco.DB.QuickDataBase.Adapter.IDataBaseAdapter adp = handler.DbAdapter;
            //创建单一参数对象
            System.Data.IDataParameter para = adp.CreateParameter("@Para", "abc");
            //快速创建参数化对象数组
            Draco.DB.QuickDataBase.IDataParameters parameters = new Draco.DB.QuickDataBase.Common.DataParameters(adp);
            parameters.AddParameterValue("FiledNameX", 1);
            parameters.AddParameterValue("FiledNameY", "abc");
            parameters.AddParameterValue("FiledNameZ", DateTime.Now);
            System.Data.IDataParameter[] _Parameters = parameters.Parameters;


            String SQL = "select * from tab where field1=? and (field2=? or field3>?)";

            Draco.DB.QuickDataBase.ParameterizedSQL param = handler.DbAdapter.AdaptSQLAnonymousParams(SQL, 100, "ABC", DateTime.Now);
            DataSet ds = handler.ExecuteQuery(param.SQL, param.Parameters);

            Draco.DB.QuickDataBase.ISQLGenerator SQLGen = adp.GetSQLGenerator();

            Draco.DB.QuickDataBase.IDataBaseSchemaHandler schemaHandler = adp.GetSchemaHandler(handler);

            String timeSQL = adp.NamedSQLs["Test.TimeSQL"];
            Object obj     = handler.ExecuteScalar(timeSQL);

            //
            ctx.Handler.StartTransaction();
            ctx.Handler.CommitTransaction();

            handler.StartTransaction();
            handler.CommitTransaction();

            using (Draco.DB.QuickDataBase.Common.DbTransactionScope scope = new DbTransactionScope(handler))
            {
                try
                {
                    //....
                    scope.Complete();//
                }
                catch { }
            }

            Draco.DB.ORM.IORMContext octx = new ORMContext(connInfo);
            Draco.DB.ORM.Schema.Vendor.ISchemaLoader   Loader    = octx.SchemaLoader;                                   //获取加载器
            Draco.DB.ORM.Schema.Dbml.Database          dataBase  = Loader.Load("Name", "Draco.DataTblCtrlLayer", null); //加载数据库构架
            Draco.DB.ORM.Generator.EntityCodeGenerator Generator = new EntityCodeGenerator(dataBase);                   //创建代码生成器
            string Code = Generator.GenerateCode("MyEntity", "GUID", true);                                             //创建C#代码

            System.IO.File.WriteAllText("D:\\MyEntity.cs", Code, System.Text.Encoding.UTF8);                            //输出C#代码到文件
        }
コード例 #18
0
 public ParameterMultiValueWrapper(System.Data.IDataParameter param)
     : base(param)
 {
 }
コード例 #19
0
 protected internal ParameterWrapper(System.Data.IDataParameter param)
     : base(param)
 {
 }