Exemplo n.º 1
0
        // Helper method: This method establishes a connection to a database
        private IBM.Data.DB2.DB2Connection ConnectDb()
        {
            String server     = txtHostName.Text.Trim();
            String alias      = txtDatabaseName.Text.Trim();
            String userId     = txtUserId.Text.Trim();
            String password   = txtPwd.Text.Trim();
            String portNumber = txtPortNumber.Text.Trim();
            String connectString;

            try
            {
                connectString = "Server=" + server + ":" + portNumber + ";Database=" + alias;
                if (userId != "")
                {
                    connectString += ";UID=" + userId + ";PWD=" + password;
                }

                IBM.Data.DB2.DB2Connection conn = new IBM.Data.DB2.DB2Connection(connectString);
                conn.Open();
                return(conn);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        static System.Data.IDbConnection GetNewTempConnection()
        {
            string connectString = Neusoft.FrameWork.Management.Connection.DataSouceString;

            if (connectString.ToLower().Trim().IndexOf("pooling=true") > 0)
            {
                connectString = connectString.Replace("True", "False");
                connectString = connectString.Replace("true", "False");
            }
            System.Data.IDbConnection conn = null;
            switch (Neusoft.FrameWork.Management.Connection.DBType)
            {
            case Neusoft.FrameWork.Management.Connection.EnumDBType.ORACLE:
                conn = new System.Data.OracleClient.OracleConnection(connectString);
                break;

            case Neusoft.FrameWork.Management.Connection.EnumDBType.DB2:
                conn = new IBM.Data.DB2.DB2Connection(Neusoft.FrameWork.Management.Connection.DataSouceString);
                break;

            case Neusoft.FrameWork.Management.Connection.EnumDBType.SQLSERVER:
                conn = new System.Data.SqlClient.SqlConnection(Neusoft.FrameWork.Management.Connection.DataSouceString);
                break;

            default:
                conn = new System.Data.OleDb.OleDbConnection(Neusoft.FrameWork.Management.Connection.DataSouceString);
                break;
            }

            return(conn);
        }
Exemplo n.º 3
0
        /// <summary>
        ///  设置连接
        /// </summary>
        /// <param name="strConnectString">连接的字符串</param>
        /// <returns>0 success -1 fail</returns>
        public int Connect(string strConnectString)
        {
            try
            {
                //显示进度
                this.ProgressBarValue = 50;
                this.ProgressBarText  = "正在连接数据库...";

                con = new IBM.Data.DB2.DB2Connection(strConnectString);
                con.Open();

                Neusoft.FrameWork.Management.Connection.Instance = con as IBM.Data.DB2.DB2Connection;//传给全局连接

                WriteDebug("连接数据库!" + strConnectString);
                this.ProgressBarValue = 0;
                return(0);
            }
            catch (Exception ex)
            {
                this.ProgressBarValue = 0;
                this.Err            = "连接数据库产生错误!" + ex.Message;
                this.ErrorException = ex.InnerException + "+ " + ex.Source;
                this.ErrCode        = "-1";
                this.WriteErr();
                return(-1);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 执行非查询语句
        /// </summary>
        /// <param name="strSql">执行sql语句</param>
        /// <returns>执行sql语句影响的行数 0执行到零行,-1没有执行有错误,对于update,insert,del外都为-1。>0成功的行数</returns>
        public int ExecNoQuery(string strSql)
        {
            //this.command=new OracleCommand();
a:
            CloseRead();
            if (Neusoft.FrameWork.Management.PublicTrans.Trans != null)
            {
                this.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans);
            }

            this.command.Connection  = this.con as IBM.Data.DB2.DB2Connection;
            this.command.CommandType = CommandType.Text;
            this.command.Parameters.Clear();

            this.command.CommandText = strSql + "";
            int i = 0;

            try
            {
                i = this.command.ExecuteNonQuery();
            }
            catch (IBM.Data.DB2.DB2Exception ex)
            {
                this.Err       = "执行产生错误!" + ex.Message;
                this.ErrCode   = strSql;
                this.DBErrCode = 1;//暂时写死,前台用这个做判断,比如先UPDATE如果返1,那么执行INSERT
                this.WriteErr();
                //if (ex.Number == 3113)
                //{
                //    while (this.Connect(this.con.ConnectionString) == -1)
                //    {
                //    }
                //    goto a;
                //}
                if (this.con.State != ConnectionState.Open)
                {
                    con.Open();
                    goto a;
                }
                return(-1);
            }
            if (i == 0)
            {
                this.Err     = "没找到相应的行数!";
                this.ErrCode = strSql;
                this.WriteErr();
            }
            WriteDebug("执行无返回sql语句!" + strSql);
            return(i);
        }
Exemplo n.º 5
0
 public void Open()
 {
     try
     {
         _DB2Conn = new IBM.Data.DB2.DB2Connection();
         _DB2Conn.ConnectionString = _connectingString;
         _DB2Conn.Open();
     }
     catch (System.Exception ex)
     {
         _DB2Conn = null;
         throw ex;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// 更新数据库的Blob数据类型,需指定sql参数为length=1的参数
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="ImageData"></param>
        /// <returns></returns>
        public int InputBlob(string strSql, byte[] ImageData)
        {
            CloseRead();
            if (Neusoft.FrameWork.Management.PublicTrans.Trans != null)
            {
                this.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans);
            }

            //   string block="INSERT INTO test_image(id,name, image) VALUES (2,'a', :blobtodb)";
            this.command.Connection = this.con as IBM.Data.DB2.DB2Connection;
            command.CommandText     = strSql + "";
            command.CommandType     = System.Data.CommandType.Text;

            string strParam = "";
            int    i        = strSql.IndexOf(":", 0);

            if (i <= 0)
            {
                this.Err = "未指定参数!" + strSql;
                this.WriteErr();
                return(-1);
            }
            strParam = strSql.Substring(i + 1, 1);
            IBM.Data.DB2.DB2Parameter param = command.Parameters.Add(strParam, IBM.Data.DB2.DB2Type.Blob);
            param.Direction = System.Data.ParameterDirection.Input;

            param.Value = ImageData;
            try
            {
                command.ExecuteNonQuery();
            }
            catch (IBM.Data.DB2.DB2Exception ex)
            {
                this.Err       = "执行产生错误!" + ex.Message;
                this.ErrCode   = strSql;
                this.DBErrCode = 1;
                this.WriteErr();
                return(-1);
            }
            catch (Exception ex)
            {
                this.Err            = ex.Message;
                this.ErrorException = ex.InnerException + "+ " + ex.Source;
                this.WriteErr();
                return(-1);
            }

            return(0);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 执行sql,返回DataSet
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="DataSet"></param>
        /// <returns></returns>
        public int ExecQuery(string strSql, ref DataSet DataSet)
        {
a:
            CloseRead();
            this.command.Connection  = this.con as IBM.Data.DB2.DB2Connection;
            this.command.CommandType = System.Data.CommandType.Text;
            this.command.Parameters.Clear();
            this.command.CommandText = strSql + "";
            try
            {
                IBM.Data.DB2.DB2DataAdapter adapter = new IBM.Data.DB2.DB2DataAdapter(this.command);
                adapter.Fill(DataSet);
            }
            catch (IBM.Data.DB2.DB2Exception ex)
            {
                this.Err       = "执行产生错误!" + ex.Message;
                this.ErrCode   = strSql;
                this.DBErrCode = 1;
                this.WriteErr();

                //[2007/11/28]先不改,下面代码是ORACLE专用的
                //if (ex.Number == 3113)
                //{
                //    while (this.Connect(this.con.ConnectionString) == -1)
                //    {
                //    }
                //    goto a;
                //}
                //end;
                if (this.con.State != ConnectionState.Open)
                {
                    this.con.Open();
                    goto a;
                }

                return(-1);
            }
            catch (Exception ex)
            {
                this.Err            = "执行语句产生错误!" + ex.Message;
                this.ErrorException = ex.InnerException + "+ " + ex.Source;
                this.ErrCode        = strSql;
                this.WriteErr();
                return(-1);
            }

            WriteDebug("执行查询sql语句!" + strSql);
            return(0);
        }
Exemplo n.º 8
0
        private void btnDB2Connection_Click(object sender, EventArgs e)
        {
            string message = string.Empty;

            try
            {
                IBM.Data.DB2.DB2Connection conn = ConnectDb();
                message = "DB2 Connection Successful !";
                conn.Close();
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            MessageBox.Show(message, "Import from DB2 Utility", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 输入长字符串
        /// 针对>4000长度的字符串
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int InputLong(string strSql, string data)
        {
            CloseRead();
            if (Neusoft.FrameWork.Management.PublicTrans.Trans != null)
            {
                this.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans);
            }
            this.command.Connection = this.con as IBM.Data.DB2.DB2Connection;
            command.CommandText     = strSql + "";
            command.CommandType     = System.Data.CommandType.Text;

            string strParam = "";
            int    i        = strSql.IndexOf(":", 0);

            if (i <= 0)
            {
                this.Err = "未指定参数!" + strSql;
                this.WriteErr();
                return(-1);
            }
            strParam = strSql.Substring(i + 1, 1);
            IBM.Data.DB2.DB2Parameter param = command.Parameters.Add(strParam, IBM.Data.DB2.DB2Type.LongVarChar);
            param.Direction = System.Data.ParameterDirection.Input;

            param.Value = data;
            try
            {
                command.ExecuteNonQuery();
            }
            catch (IBM.Data.DB2.DB2Exception ex)
            {
                this.Err       = "执行产生错误!" + ex.Message;
                this.ErrCode   = strSql;
                this.DBErrCode = 1;
                this.WriteErr();
                return(-1);
            }
            catch (Exception ex)
            {
                this.Err            = ex.Message;
                this.ErrorException = ex.InnerException + "+ " + ex.Source;
                this.WriteErr();
                return(-1);
            }

            return(0);
        }
Exemplo n.º 10
0
        private void btnPublishData_Click(object sender, EventArgs e)
        {
            string sQuery1 = string.Empty;
            string sQuery2 = string.Empty;
            string sQuery3 = string.Empty;
            string message = string.Empty;

            IBM.Data.DB2.DB2Connection conn = null;
            DataTable dt = new DataTable("Table1");

            try
            {
                conn = ConnectDb();
                switch (cmbTransactionType.SelectedIndex)
                {
                case 0:
                    sQuery1 = "SELECT * FROM DEPOSIT FETCH FIRST 5 ROWS ONLY";
                    break;

                case 1:
                    sQuery1 = "SELECT * FROM LOAN FETCH FIRST 5 ROWS ONLY";
                    break;
                }
                using (IBM.Data.DB2.DB2Command cmd = new IBM.Data.DB2.DB2Command(sQuery1, conn))
                {
                    IBM.Data.DB2.DB2DataReader dr = cmd.ExecuteReader();
                    dt.Load(dr);
                }
                conn.Close();
                if (dt.Rows.Count <= 0)
                {
                    message = "No Record Exist !!!";
                }
                else
                {
                    SaveData(dt);
                    message = "Successfully Imported '" + cmbTransactionType.Text + "' Data !!!";
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            MessageBox.Show(message, "Import from DB2 Utility", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 11
0
        public void Close()
        {
            if (_DB2Conn == null)
            {
                return;
            }

            try
            {
                _DB2Conn.Close();
                _DB2Conn.Dispose();
                _DB2Conn = null;
            }
            catch (System.Exception ex)
            {
                _DB2Conn = null;
                throw ex;
            }
        }
Exemplo n.º 12
0
        /*
         * Método que trae todos los datos de la tabla TOOL_SETUP_INFO por toolId
         */
        private static DataTable bringResultsForToolId(string toolIdToSearch)
        {
            IBM.Data.DB2.DB2Connection conn = null;
            DataTable dt = new DataTable("Table1");

            conn = ConnectDb();

            string queryDbGetRequestedDataForToolKey =
                @"SELECT TS_INFO_KEY, PRODUCT_PN_KEY, TOOL_KEY, ROUTE_STEP_KEY, LAST_CHANGE_TMST, RECIPE_READY, RECIPE_ID, PROGRAM_ID, CARRIER_PN_KEY, DUAL_SIDED, DUAL_LANE, PFC_MODE, LAST_SETUP_TOOL_KEY, LAST_SETUP_TOOL_STAGE
                    FROM CGSLSC.TOOL_SETUP_INFO
                    WHERE (TOOL_KEY = " + toolIdToSearch + ") ORDER BY LAST_CHANGE_TMST DESC";

            using (IBM.Data.DB2.DB2Command cmd = new IBM.Data.DB2.DB2Command(queryDbGetRequestedDataForToolKey, conn))
            {
                IBM.Data.DB2.DB2DataReader dr = cmd.ExecuteReader();
                dt.Load(dr);
            }
            conn.Close();
            return(dt);
        }
Exemplo n.º 13
0
        /*
         * Método que devuelve el nombre del part number ID
         */
        private static DataTable bringResultsForProductPN(string _ProductPartNumberId)
        {
            IBM.Data.DB2.DB2Connection conn = null;
            DataTable dt = new DataTable("Table1");

            conn = ConnectDb();

            string queryDbGetRequestedDataForPN =
                @" SELECT PART_NUMBER_KEY AS EXPR1, CGS.PART_NUMBER.*
                    FROM CGS.PART_NUMBER
                    WHERE (PART_NUMBER_KEY = " + _ProductPartNumberId + ")";

            using (IBM.Data.DB2.DB2Command cmd = new IBM.Data.DB2.DB2Command(queryDbGetRequestedDataForPN, conn))
            {
                IBM.Data.DB2.DB2DataReader dr = cmd.ExecuteReader();
                dt.Load(dr);
            }
            conn.Close();
            return(dt);
        }
Exemplo n.º 14
0
        /*
         * Método que trae las posiciones que dispone cada part number.
         */
        private static DataTable bringResultsForPositions(string toolIdToSearch, string _ProductPartNumberId)
        {
            IBM.Data.DB2.DB2Connection conn = null;
            DataTable dt = new DataTable("Table1");

            conn = ConnectDb();

            string queryDbGetRequestedDataForPositions =
                @" SELECT CGSLSC.TOOL_SETUP.*, TOOL_KEY AS EXPR1, PRODUCT_PN_KEY AS EXPR2
                    FROM CGSLSC.TOOL_SETUP
                    WHERE (TOOL_KEY = " + toolIdToSearch + ") AND (PRODUCT_PN_KEY = " + _ProductPartNumberId + ")";

            using (IBM.Data.DB2.DB2Command cmd = new IBM.Data.DB2.DB2Command(queryDbGetRequestedDataForPositions, conn))
            {
                IBM.Data.DB2.DB2DataReader dr = cmd.ExecuteReader();
                dt.Load(dr);
            }
            conn.Close();
            return(dt);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 加载内存 判断是否debug 非公开
        /// </summary>
        /// <param name="errLogoFileName">errLogoFileName</param>
        private void newDatabase(string errLogoFileName)
        {
            if (this.con == null)
            {
                con = new IBM.Data.DB2.DB2Connection();
            }
            command = new IBM.Data.DB2.DB2Command();
            this.command.Connection = con as IBM.Data.DB2.DB2Connection;

            Logo = new Neusoft.FrameWork.Models.NeuLog(errLogoFileName);
            string debugLogoFileName = "./debugSql.log";

            if (System.IO.File.Exists(debugLogoFileName))
            {
                debugLogo = new Neusoft.FrameWork.Models.NeuLog(debugLogoFileName);
                bDebug    = true;
            }
            else
            {
                bDebug = false;
            }
        }
Exemplo n.º 16
0
        /*
         * Método que conecta con la base de datos.
         */
        private static IBM.Data.DB2.DB2Connection ConnectDb()
        {
            String userId   = "sromero";
            String password = "******";
            String connectString;
            string message = string.Empty;

            try
            {
                connectString = "Database=CGS;Server=ARUS3DB03.nwsn.local:50000;Persist Security Info=True";
                string letMeIn = "Database=CGS;Server=ARUS3DB06.nwsn.local:50000;Persist Security Info=True";
                if (userId != "")
                {
                    letMeIn += ";UID=" + userId + ";PWD=" + password;
                }

                IBM.Data.DB2.DB2Connection conn = new IBM.Data.DB2.DB2Connection(letMeIn);
                conn.Open();
                message = "DB2 Cennexion exitosa !";
                return(conn);
            }
            catch (Exception)
            { throw; }
        }
Exemplo n.º 17
0
        /// <summary>
        /// 获得连接
        /// </summary>
        /// <returns></returns>
        static System.Data.IDbConnection GetNewConnection()
        {
            System.Data.IDbConnection conn = null;
            switch (Neusoft.FrameWork.Management.Connection.DBType)
            {
            case Neusoft.FrameWork.Management.Connection.EnumDBType.ORACLE:
                conn = new System.Data.OracleClient.OracleConnection(Neusoft.FrameWork.Management.Connection.DataSouceString);
                break;

            case Neusoft.FrameWork.Management.Connection.EnumDBType.DB2:
                conn = new IBM.Data.DB2.DB2Connection(Neusoft.FrameWork.Management.Connection.DataSouceString);
                break;

            case Neusoft.FrameWork.Management.Connection.EnumDBType.SQLSERVER:
                conn = new System.Data.SqlClient.SqlConnection(Neusoft.FrameWork.Management.Connection.DataSouceString);
                break;

            default:
                conn = new System.Data.OleDb.OleDbConnection(Neusoft.FrameWork.Management.Connection.DataSouceString);
                break;
            }

            return(conn);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 执行查询语句,返回Reader
        /// </summary>
        /// <param name="strSql">执行sql语句</param>
        /// <returns>0 success -1 fail</returns>
        public int ExecQuery(string strSql, ref IBM.Data.DB2.DB2DataReader Reader)
        {
            //this.command=new OracleCommand();
a:

            CloseRead();

            this.command.Connection = this.con as IBM.Data.DB2.DB2Connection;


            //this.command.Connection.Close();
            //this.command.Connection.Open();

            this.command.CommandType = System.Data.CommandType.Text;
            this.command.CommandText = strSql + "";
            this.command.Parameters.Clear();
            try
            {
                Reader = this.command.ExecuteReader();

                //Reader.FetchSize = this.command.RowSize * 10000;//这行代码先注释掉,可能需要改动[2007/11/28]肿瘤医院
            }
            catch (IBM.Data.DB2.DB2Exception ex)
            {
                this.Err       = "执行产生错误!" + ex.Message;
                this.ErrCode   = strSql;
                this.DBErrCode = 1;
                this.WriteErr();

                //新增[2007/11/29]
                //trans.Rollback();
                //end;

                //下面代码可能是如果断开连接,那么重新连接,下面代码是ORACLE专用的,一会儿再改为DB2的[2007/11/28]
                //if (ex.Number == 3113)
                //{
                //    while (this.Connect(this.con.ConnectionString) == -1)
                //    {
                //    }
                //    goto a;
                //}
                // end;
                if (this.con.State != ConnectionState.Open)
                {
                    this.con.Open();
                    goto a;
                }


                return(-1);
            }
            catch (Exception ex)
            {
                //trans.Rollback();//新增[2007/11/29]

                this.Err            = "执行产生错误!" + ex.Message;
                this.ErrorException = ex.InnerException + "+ " + ex.Source;
                this.ErrCode        = strSql;
                this.WriteErr();
            }

            //trans.Commit();//新增[2007/11/29]


            WriteDebug("执行查询sql语句!" + strSql);
            return(0);
        }
Exemplo n.º 19
0
        /// <summary>
        /// 执行sql语句 重载
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="strDataSet">返回DataSet xml</param>
        /// <returns></returns>
        public int ExecQuery(string strSql, ref string strDataSet)
        {
            //[2007/12/01]新增
            //if (TempReader1 != null)
            //{
            //    if (!TempReader1.IsClosed)
            //    {
            //        TempReader1.Close();
            //    }
            //}
            // end;

            //[2008/03/13]
            //if (reader != null)
            //{
            //    if (!reader.IsClosed)
            //    {
            //        reader.Close();
            //    }
            //}
            //END

            CloseRead();
            if (Neusoft.FrameWork.Management.PublicTrans.Trans != null)
            {
                this.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans);
            }

            this.command.Connection  = this.con as IBM.Data.DB2.DB2Connection;
            this.command.CommandType = System.Data.CommandType.Text;
            this.command.Parameters.Clear();
            this.command.CommandText = strSql + "";
            try
            {
                TempReader1 = this.command.ExecuteReader();
                //TempReader1.FetchSize = this.command.RowSize * 10000;[2007/11/28]

                XmlDocument doc = new XmlDocument();
                XmlNode     root;
                XmlNode     node, table;
                root = doc.CreateElement("DataSet");
                doc.AppendChild(root);
                while (TempReader1.Read())
                {
                    table = doc.CreateElement("Table");
                    for (int i = 0; i < TempReader1.FieldCount; i++)
                    {
                        node           = doc.CreateElement(TempReader1.GetName(i).ToString());
                        node.InnerText = TempReader1[i].ToString() + "";
                        table.AppendChild(node);
                    }
                    root.AppendChild(table);
                }
                strDataSet = doc.OuterXml;
                TempReader1.Close();
            }
            catch (IBM.Data.DB2.DB2Exception ex)
            {
                this.Err       = "执行产生错误!" + ex.Message;
                this.ErrCode   = strSql;
                this.DBErrCode = 1;
                this.WriteErr();

                return(-1);
            }
            catch (Exception ex)
            {
                this.Err            = "执行语句产生错误!" + ex.Message;
                this.ErrorException = ex.InnerException + "+ " + ex.Source;
                this.ErrCode        = strSql;
                this.WriteErr();

                return(-1);
            }

            WriteDebug("执行查询sql语句!" + strSql);
            return(0);
        }
Exemplo n.º 20
0
        /// <summary>
        /// 执行存储过程
        /// <example>PRC_HIEBILL_CHARGE_ext,arg_checkopercode,22,1,{0},
        ///  arg_exec_Sqn,22,1,{1},arg_yearcode,22,1,{2},return_code,30,2,{3},return_result,22,2,{4}</example>
        /// </summary>
        /// <param name="strSql">存储过程-参数,类型,输入输出,数值<br>22 varchar 30 double 33 int 6 DATETIME </br></param>
        /// <param name="Return">存储过程返回值 逗号分割</param>
        /// <returns>0 成功 -1 失败</returns>
        public int ExecEvent(string strSql, ref string Return)
        {
            CloseRead();
            this.command.CommandType = System.Data.CommandType.StoredProcedure;
            this.command.Connection  = this.con as IBM.Data.DB2.DB2Connection;
            this.command.Parameters.Clear();
            string prcName = "";

            string[] prcParams = strSql.Split(',');
            try
            {
                prcName = prcParams[0];
                this.command.CommandText = prcName;
                //'22 varchar 30 double 33 int 6 DATETIME
                for (int i = 1; i < prcParams.GetUpperBound(0); i = i + 4)
                {
                    IBM.Data.DB2.DB2Parameter param = new IBM.Data.DB2.DB2Parameter();
                    param.ParameterName = prcParams[i].Trim();
                    switch (int.Parse(prcParams[i + 1]))
                    {
                    case 22:
                        param.DB2Type = IBM.Data.DB2.DB2Type.VarChar;
                        break;

                    case 30:
                        param.DB2Type = IBM.Data.DB2.DB2Type.Double;
                        break;

                    case 6:
                        param.DB2Type = IBM.Data.DB2.DB2Type.Timestamp;
                        break;

                    case 33:
                        param.DB2Type = IBM.Data.DB2.DB2Type.Integer;
                        break;

                    case 13:
                        param.DB2Type = IBM.Data.DB2.DB2Type.BigInt;
                        break;

                    case 28:
                        param.DB2Type = IBM.Data.DB2.DB2Type.BigInt;
                        break;

                    default:
                        param.DB2Type = IBM.Data.DB2.DB2Type.VarChar;
                        break;
                    }

                    param.Direction = (System.Data.ParameterDirection) int.Parse(prcParams[i + 2]);
                    if (param.Direction == System.Data.ParameterDirection.Input)
                    {
                        param.Value = prcParams[i + 3].Trim();
                        param.Size  = 50;
                    }
                    else if (param.DB2Type == IBM.Data.DB2.DB2Type.VarChar)
                    {
                        param.Size = 50;
                    }
                    this.command.Parameters.Add(param);
                }
                this.command.ExecuteNonQuery();
            }
            catch (IBM.Data.DB2.DB2Exception ex)
            {
                this.Err       = "执行产生错误!" + ex.Message;
                this.ErrCode   = strSql;
                this.DBErrCode = 1;
                this.WriteErr();
                return(-1);
            }
            catch (Exception ex)
            {
                this.Err            = "执行存储过程出错!" + strSql + ex.Message;
                this.ErrorException = ex.InnerException + "+ " + ex.Source;
                this.WriteErr();
                return(-1);
            }

            try
            {
                for (int i = 0; i < this.command.Parameters.Count; i++)
                {
                    if (this.command.Parameters[i].Direction == System.Data.ParameterDirection.Output)
                    {
                        Return = Return + "," + this.command.Parameters[i].Value;
                    }
                }
                Return = Return.Substring(1);
            }
            catch (Exception ex)
            {
                this.Err = "执行存储过程出错!" + strSql + ex.Message;
                this.WriteErr();
                return(-1);
            }

            return(0);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 执行sql
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="strDataSet"></param>
        /// <returns></returns>
        public int ExecQuery(string strSql, ref string strDataSet, string strXSLFileName)
        {
            //[2007/12/01]新增
            CloseRead();
            // end;

            //[2008/03/13]
            //if (reader != null)
            //{
            //    if (!reader.IsClosed)
            //    {
            //        reader.Close();
            //    }
            //}
            // end;


            this.command.Connection  = this.con as IBM.Data.DB2.DB2Connection;
            this.command.CommandType = System.Data.CommandType.Text;
            this.command.Parameters.Clear();
            this.command.CommandText = strSql + "";
            try
            {
                TempReader1 = this.command.ExecuteReader();
                XmlDocument doc = new XmlDocument();
                XmlNode     root;
                XmlElement  node, row;
                doc.AppendChild(doc.CreateXmlDeclaration("1.0", "GB2312", ""));
                if (strXSLFileName != null && strXSLFileName != "")
                {
                    string PI = "type='text/xsl' href='" + strXSLFileName + "'";
                    System.Xml.XmlProcessingInstruction xmlProcessingInstruction = doc.CreateProcessingInstruction("xml-stylesheet", PI);
                    doc.AppendChild(xmlProcessingInstruction);
                }
                root = doc.CreateElement("Table");
                doc.AppendChild(root);
                while (TempReader1.Read())
                {
                    row = doc.CreateElement("Row");
                    for (int i = 0; i < TempReader1.FieldCount; i++)
                    {
                        node = doc.CreateElement("Column");
                        node.SetAttribute("Name", TempReader1.GetName(i).ToString());
                        node.InnerText = TempReader1[i].ToString() + "";
                        row.AppendChild(node);
                    }
                    root.AppendChild(row);
                }
                strDataSet = doc.OuterXml;
                TempReader1.Close();
            }
            catch (IBM.Data.DB2.DB2Exception ex)
            {
                this.Err       = "执行产生错误!" + ex.Message;
                this.ErrCode   = strSql;
                this.DBErrCode = 1;
                this.WriteErr();
                return(-1);
            }
            catch (Exception ex)
            {
                this.Err            = "执行语句产生错误!" + ex.Message;
                this.ErrorException = ex.InnerException + "+ " + ex.Source;
                this.ErrCode        = strSql;
                this.WriteErr();
                return(-1);
            }

            WriteDebug("执行查询sql语句!" + strSql);
            return(0);
        }
Exemplo n.º 22
0
 public DB2Command(string commandStr, IBM.Data.DB2.DB2Connection con, IBM.Data.DB2.DB2Transaction trans)
 {
 }
Exemplo n.º 23
0
 public DB2Command(string commandStr, IBM.Data.DB2.DB2Connection con)
 {
 }
Exemplo n.º 24
0
 public DB2DataAdapter(string selectCommandText, IBM.Data.DB2.DB2Connection selectConnection)
 {
 }
Exemplo n.º 25
0
 public static void DB2CheckReturn(short sqlRet, short handleType, System.IntPtr handle, string message, IBM.Data.DB2.DB2Connection connection)
 {
 }