All pastes #21790 Raw Edit

Miscellany

public text v1 · immutable
#21790 ·published 2005-09-01 00:50 UTC
rendered paste body
        public int UpdateRateCentreInfo(NpgsqlConnection oConn)
        {
            int iRet = 0;

            //-- we need to make sure that we have data in the properties
            if (oConn.State == ConnectionState.Open)
            {
                //-- build the stored procedure T-SQL
                System.Text.StringBuilder sb = new System.Text.StringBuilder();

                sb.Append("SELECT sp_UpdateRateCentreInfo(");
                sb.Append(m_RateCentreID + ", ");
                sb.Append("'" + m_Name.Replace("'", "''") + "');");

                //-- attempt to execute the SQL statement
                try
                {
                    NpgsqlCommand oCmd = new NpgsqlCommand(sb.ToString(), oConn);
                    oCmd.CommandType = CommandType.Text;

                    NpgsqlDataReader oRdr = oCmd.ExecuteReader(CommandBehavior.SingleRow);

                    oRdr.Read();

                    if (oRdr.HasRows)
                        iRet = Convert.ToInt16(oRdr[0].ToString());
                    else
                        iRet = 0;

                    oRdr.Close();

                }
                catch (NpgsqlException ex)
                {
                    m_ErrorText = ex.Message + "\r\n" + sb.ToString();
                    iRet = -2;
                }
            }
            else
            {
                //-- database connection not open
                iRet = -1;
            }

            return iRet;
        }