コード例 #1
0
        public static MEMBERS.SQLReturnValue ExecuteNoneQuery(string QueryString)
        {
            SqlConnection conn = new SqlConnection(conStr);

            MEMBERS.SQLReturnValue m = new MEMBERS.SQLReturnValue();
            try
            {
                SqlCommand cmd = new SqlCommand(QueryString, conn);
                cmd.CommandType    = CommandType.Text;
                cmd.CommandTimeout = 0;
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            { throw ex; }
            finally
            { if (conn.State == ConnectionState.Open)
              {
                  conn.Close();
              }
            }
            return(m);
        }
コード例 #2
0
        public static MEMBERS.SQLReturnValue ExecuteNoneQueryWithPera(string QueryString, string[,] paramvalue)
        {
            SqlConnection conn = new SqlConnection(conStr);

            MEMBERS.SQLReturnValue m = new MEMBERS.SQLReturnValue();
            try
            {
                SqlCommand cmd = new SqlCommand(QueryString, conn);

                SqlParameter[] param = new SqlParameter[paramvalue.GetUpperBound(0) + 1];
                for (int i = 0; i < param.Length; i++)
                {
                    param[i] = new SqlParameter("@" + paramvalue[i, 0].ToString(), paramvalue[i, 1].ToString());
                }

                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddRange(param);
                cmd.CommandTimeout = 0;
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            { throw ex; }
            finally
            { if (conn.State == ConnectionState.Open)
              {
                  conn.Close();
              }
            }
            return(m);
        }
コード例 #3
0
        //------------------------------------Parameter With Datatable----------------------------------------------
        public static MEMBERS.SQLReturnValue ExecuteProcedureWithDatatable(string ProcedureName, string[,] ParamValue, DataTable dtExamAnswer, string TableParamName)
        {
            SqlConnection MYCON = new SqlConnection(conStr);

            MEMBERS.SQLReturnValue m = new MEMBERS.SQLReturnValue();
            try
            {
                SqlCommand COMMAND = new SqlCommand(ProcedureName, MYCON);
                COMMAND.CommandTimeout = 0;
                COMMAND.CommandType    = CommandType.StoredProcedure;
                SqlParameter[] param = new SqlParameter[ParamValue.GetUpperBound(0) + 1];
                for (int i = 0; i < param.Length; i++)
                {
                    param[i] = new SqlParameter("@" + ParamValue[i, 0].ToString(), ParamValue[i, 1].ToString());
                }

                COMMAND.Parameters.AddRange(param);
                if (dtExamAnswer != null)
                {
                    SqlParameter ParamTb = new SqlParameter("@" + TableParamName, dtExamAnswer);
                    ParamTb.SqlDbType = SqlDbType.Structured;
                    COMMAND.Parameters.Add(ParamTb);
                }
                COMMAND.Parameters.Add("OUTVAL", SqlDbType.VarChar, 50).Direction       = ParameterDirection.Output;
                COMMAND.Parameters.Add("OUTMESSAGE", SqlDbType.VarChar, 1000).Direction = ParameterDirection.Output;

                if (MYCON.State != ConnectionState.Open)
                {
                    MYCON.Open();
                }
                COMMAND.ExecuteNonQuery();

                m.OUTMESSAGE = COMMAND.Parameters["OUTMESSAGE"].Value.ToString();
                m.Outval     = COMMAND.Parameters["OUTVAL"].Value.ToString();
                //return m;
            }
            catch (Exception ex)
            { throw ex; }
            finally
            { if (MYCON.State == ConnectionState.Open)
              {
                  MYCON.Close();
              }
            }
            return(m);
        }
コード例 #4
0
        protected static MEMBERS.SQLReturnValue ExecuteNoneQueryWithMessage(string ProceduerName, string[,] paramvalue, bool AddOutputparameter)
        {
            SqlConnection conn = new SqlConnection(conStr);

            MEMBERS.SQLReturnValue m = new MEMBERS.SQLReturnValue();
            try
            {
                SqlCommand cmd = new SqlCommand(ProceduerName, conn);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 0;
                SqlParameter[] param = new SqlParameter[paramvalue.GetUpperBound(0) + 1];
                for (int i = 0; i < param.Length; i++)
                {
                    param[i] = new SqlParameter("@" + paramvalue[i, 0].ToString(), paramvalue[i, 1].ToString());
                }

                cmd.Parameters.AddRange(param);
                if (AddOutputparameter)
                {
                    cmd.Parameters.Add("OUTVAL", SqlDbType.VarChar, 50).Direction       = ParameterDirection.Output;
                    cmd.Parameters.Add("OUTMESSAGE", SqlDbType.VarChar, 1000).Direction = ParameterDirection.Output;
                }
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                cmd.ExecuteNonQuery();
                m.OUTMESSAGE = cmd.Parameters["OUTMESSAGE"].Value.ToString();
                m.Outval     = cmd.Parameters["OUTVAL"].Value.ToString();
            }
            catch (Exception ex)
            { throw ex; }
            finally
            { if (conn.State == ConnectionState.Open)
              {
                  conn.Close();
              }
            }
            return(m);
        }