コード例 #1
0
        private DataRow ReturnDataRow(string SelectQuery, CommandType cmdType)
        {
            DataTable     dt;
            SqlConnection conn = null;

            try
            {
                SqlCmd = new SqlCommand();
                dt     = new DataTable();
                conn   = ClsConnection.OpenConnectiion();

                SqlCmd.Connection  = conn;
                SqlCmd.CommandText = SelectQuery;
                SqlCmd.CommandType = cmdType;
                SqlAdp             = new SqlDataAdapter(SqlCmd);
                SqlAdp.Fill(dt);

                return(dt.Rows[0]);
            }

            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Dispose();
                SqlCmd = null;
            }
        }
コード例 #2
0
        private DataRow ReturnDataRow(string SelectQuery, SqlParameter[] _SqlParameter, CommandType cmdType)
        {
            DataTable     dt;
            SqlConnection conn = null;

            try
            {
                SqlCmd = new SqlCommand();
                dt     = new DataTable();
                conn   = ClsConnection.OpenConnectiion();

                SqlCmd.Connection     = conn;
                SqlCmd.CommandText    = SelectQuery;
                SqlCmd.CommandType    = cmdType;
                SqlCmd.CommandTimeout = 60;
                for (int i = 0; i < _SqlParameter.Length; i++)
                {
                    SqlCmd.Parameters.Add(_SqlParameter[i]);
                }

                SqlAdp = new SqlDataAdapter(SqlCmd);
                SqlAdp.Fill(dt);
                if (dt.Rows.Count == 0)
                {
                    return(null);
                }

                return(dt.Rows[0]);
            }

            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Dispose();
                SqlCmd = null;
            }
        }
コード例 #3
0
        public int ExecuteIdentity(string cmdText, SqlParameter[] _SqlParameter, CommandType cmdType = CommandType.StoredProcedure)
        {
            int linkID = 0;

            try
            {
                using (SqlConnection con = new SqlConnection(ClsConnection.GetConnection().ConnectionString))
                {
                    con.Open();
                    SqlCmd            = new SqlCommand();
                    SqlCmd.Connection = con;

                    for (int i = 0; i < _SqlParameter.Length; i++)
                    {
                        SqlCmd.Parameters.Add(_SqlParameter[i]);
                    }


                    if (cmdType == CommandType.StoredProcedure)
                    {
                        SqlCmd.CommandType = CommandType.StoredProcedure;
                        SqlCmd.CommandText = cmdText;
                    }
                    else
                    {
                        cmdText           += " SELECT CAST(scope_identity()as int)";
                        SqlCmd.CommandType = CommandType.Text;
                        SqlCmd.CommandText = cmdText;
                    }
                    linkID = (int)SqlCmd.ExecuteScalar();
                    return(linkID);
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
        public int Executes(string cmdText, SqlParameter[] _SqlParameter, CommandType cmdType = CommandType.StoredProcedure)
        {
            int NoOfRowsEffected = 0;

            SqlCmd = new SqlCommand();
            SqlConnection conn = null;

            try
            {
                conn = ClsConnection.OpenConnectiion();
                SqlCmd.Connection     = conn;
                SqlCmd.CommandType    = cmdType;
                SqlCmd.CommandText    = cmdText;
                SqlCmd.CommandTimeout = 600;
                for (int i = 0; i < _SqlParameter.Length; i++)
                {
                    SqlCmd.Parameters.Add(_SqlParameter[i]);
                }
                NoOfRowsEffected = SqlCmd.ExecuteNonQuery();
                return(NoOfRowsEffected);
            }

            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Dispose();
                SqlCmd = null;
            }
        }