Stored Procedure Helper Functions


    public SqlDataReader executeSPHelper(string cmdStr, ArrayList cmdParams)
    {

        SqlDataReader rd = null;
        SqlCommand sqlCmd = null;

        try
        {
            sqlCmd = new SqlCommand(cmdStr, yourConnection);
            sqlCmd.CommandType = CommandType.StoredProcedure;

            foreach (SqlParameter sqlParam in cmdParams)
            {
                sqlCmd.Parameters.Add(sqlParam);
            }

            rd = sqlCmd.ExecuteReader();

            return rd;
        }

        catch (Exception e)
        {
        }
        finally
        {
            sqlCmd = null;
        }
    }

    public System.Data.SqlClient.SqlCommand executeSPCommandHelper(string cmdStr, ArrayList cmdParams)
    {

        SqlCommand sqlCmd = null;

        try
        {
            sqlCmd = new SqlCommand(cmdStr, yourConnection);
            sqlCmd.CommandType = CommandType.StoredProcedure;

            foreach (SqlParameter sqlParam in cmdParams)
            {
                sqlCmd.Parameters.Add(sqlParam);
            }

            //rd = sqlCmd.ExecuteReader();

            return sqlCmd;
        }

        catch (Exception e)
        {

        }
        finally
        {
            sqlCmd = null;
        }
    }

    public System.Data.SqlClient.SqlCommand executeSPCommandHelper(string cmdStr)
    {

        SqlCommand sqlCmd = null;

        try
        {
            sqlCmd = new SqlCommand(cmdStr, yourConnection);
            sqlCmd.CommandType = CommandType.StoredProcedure;

            return sqlCmd;
        }

        catch (Exception e)
        {
        }
        finally
        {
            sqlCmd = null;
        }
    }

Advertisements
Posted in C#. Tags: , . Leave a Comment »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: