Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
Example #1
1
        public static string SP_Tender_FindRecord(string ProcessId, ref DataSet ReturnDs)
        {
            SqlConnection sqlConn = new SqlConnection();  //defines database connection
            SqlCommand sqlCmd = new SqlCommand();  //defines what to do
            SqlDataAdapter sqlAdap = new SqlDataAdapter();

            try
            {
                sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["AMS_MasterConnectionString"].ToString();
                sqlConn.Open();

                sqlCmd.CommandText = "SP_Tender_FindRecord";
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Connection = sqlConn;

                SqlParameter parm1 = new SqlParameter("@ProcessId", SqlDbType.VarChar);
                parm1.Value = ProcessId;
                parm1.Direction = ParameterDirection.Input;
                sqlCmd.Parameters.Add(parm1);

                sqlAdap.SelectCommand = sqlCmd;
                sqlAdap.Fill(ReturnDs);

                return string.Empty;

            }
            catch (Exception err)
            {
                return err.Message;
            }
            finally
            { sqlConn.Close(); sqlConn.Dispose(); sqlAdap.Dispose(); }
        }
        public InvoiceObject getInvoiceInfo(int invoice_Number, string connectionString, UserObject user)
        {
            DataTable results = new DataTable();

            try
            {
                conn = DBUtility.createConnection(connectionString);
                SqlCommand cmdIns = DBUtility.PrepareReadCommand("GetAnInvoice", conn);
                cmdIns.Parameters.Add( new SqlParameter("@Invoice_Number", invoice_Number));

                using (conn)
                using (cmdIns)
                using (SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdIns))
                {
                    dataAdapter.Fill(results);
                }

                var invoice = populateInvoice(results.Rows[0], connectionString, user);

                cmdIns.Dispose();
                DBUtility.Close(conn);
                conn.Dispose();
                return invoice;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString(), ex);
            }
            finally
            {
                DBUtility.Close(conn);
                conn.Dispose();

            }
        }
    protected void btnBookFlight_Click(object sender, EventArgs e)
    {
        SqlConnection objCon = new SqlConnection(strCon);

        try
        {
            objCon.ConnectionString = strCon;
            objCon.Open();
        }
        catch (Exception ex)
        {
            this.lblConnect.Text = "Unable to connect to database.";
        }

        if (objCon.State == System.Data.ConnectionState.Open)
        {
            InsertFlightInfo();
            InsertFlightOrder();

            objCon.Close();
            objCon.Dispose();
        }
        else
        {
            lblConnect.Text = "Unable to connect to database.";
            objCon.Close();
            objCon.Dispose();

        }
        objCon.Close();
        objCon.Dispose();

        redirectToNextPage();
    }
        public DataTable getAllVehicles(string connectionString)
        {
            DataTable results = new DataTable();

            try
            {
                conn = DBUtility.createConnection(connectionString);
                SqlCommand cmdIns = DBUtility.PrepareReadCommand("sp_GetAllVehicles", conn);

                using (conn)
                using (cmdIns)
                using (SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdIns))
                {
                    dataAdapter.Fill(results);
                }

                cmdIns.Dispose();
                DBUtility.Close(conn);
                conn.Dispose();
                return results;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString(), ex);
            }
            finally
            {
                DBUtility.Close(conn);
                conn.Dispose();

            }
        }
    public static void ExecuteMyQuery(string Query)
    {
        string conString = System.Configuration.ConfigurationManager.ConnectionStrings["constrww"].ToString();
        SqlConnection Connection = new SqlConnection(conString);
        Connection.Open();
        SqlCommand cmdXls = new SqlCommand(Query, Connection);

        try
        {
            cmdXls.ExecuteNonQuery();
        }
        catch (Exception e)
        {

            cmdXls.Dispose();

            Connection.Dispose();
        }
        finally
        {

            cmdXls.Dispose();

            Connection.Dispose();

        }
    }
        public DataTable getAModel(string connectionString, int modelID)
        {
            DataTable results = new DataTable();

            try
            {
                conn = DBUtility.createConnection(connectionString);
                SqlCommand cmdIns = DBUtility.PrepareReadCommand("GetAModel", conn);

                cmdIns.Parameters.Add(new SqlParameter("@Model_ID", modelID));

                using (conn)
                using (cmdIns)
                using (SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdIns))
                {
                    dataAdapter.Fill(results);
                }

                cmdIns.Dispose();
                DBUtility.Close(conn);
                conn.Dispose();
                return results;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString(), ex);
            }
            finally
            {
                DBUtility.Close(conn);
                conn.Dispose();

            }
        }
Example #7
0
        public static bool AddTaskReplyAttachments(string taskid, string replyid, List<Attachment> attachments,string userid,string clientid)
        {
            SqlConnection conn = new SqlConnection(TaskDAL.ConnectionString);
            conn.Open();
            SqlTransaction tran = conn.BeginTransaction();


            foreach (var attachment in attachments)
            {
                if (!TaskDAL.BaseProvider.AddTaskReplyAttachment(taskid,replyid,attachment.Type,
                    attachment.ServerUrl,attachment.FilePath,attachment.FileName,attachment.OriginalName,attachment.ThumbnailName,attachment.Size,
                    userid,clientid, tran))
                {
                    tran.Rollback();
                    conn.Dispose();

                    return false;
                }
            }

            tran.Commit();
            conn.Dispose();

            return true;
        }
        public void insert(UserObject userObj, string connectionString)
        {
            try
            {
                conn = DBUtility.createConnection(connectionString);
                SqlCommand cmdIns = DBUtility.PrepareSPCommand("sp_InsertCompany", insertParameters(userObj), conn);

                cmdIns.ExecuteNonQuery();

                //    cmdIns.Parameters.Clear();
                //    cmdIns.CommandText = "SELECT @@IDENTITY";

                //    // Get the last inserted id.
                //    int insertID = Convert.ToInt32(cmdIns.ExecuteScalar());

                cmdIns.Dispose();
                DBUtility.Close(conn);
                conn.Dispose();

            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString(), ex);
            }
            finally
            {
                DBUtility.Close(conn);
                conn.Dispose();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string sConnectionString = "data source=cypress.csil.sfu.ca;" + "initial catalog=hga13354;" + "Trusted_Connection=yes;";
                SqlConnection objConn = new SqlConnection(sConnectionString);
                objConn.Open();

                SqlCommand cmd = new SqlCommand("select s_ID, s_pw from dbo.Student where s_ID= '" + textBox1.Text + "'  and s_pw= '" + textBox2.Text + "' ", objConn);
                SqlDataReader sdr = cmd.ExecuteReader();
                sdr.Read();

                if (sdr.HasRows)
                { 
                    Form_search f2 = new Form_search();
                    f2.s_IS = textBox1.Text.ToString();
                    this.Hide();
                    f2.Show();
                    objConn.Close();
                    objConn.Dispose();
                }
                else
                {
                    MessageBox.Show("Incorrect Student ID or Password");
                    objConn.Close();
                    objConn.Dispose();
                }
                objConn.Close();
                objConn.Dispose();
            }
            catch (SqlException sqlEx) { MessageBox.Show("SQL Server Error Message:" + sqlEx.Message); }
           
        }
Example #10
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            int entero = 0;
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            ch = new Configuracion.Core.ConfiguracionHelper();
            ch.Command = cmd;

            try
            {
                cnx.Open();
                ch.actualizarValorConfiguracion(1, txtCorreoEmisor.Text);
                ch.actualizarValorConfiguracion(2, txtPassword.Text);
                ch.actualizarValorConfiguracion(3, txtPuerto.Text);
                entero = Convert.ToInt32(chkSsl.Checked);
                ch.actualizarValorConfiguracion(4, entero.ToString());
                ch.actualizarValorConfiguracion(5, txtServidorEnvio.Text);
                ch.actualizarValorConfiguracion(6, txtRuta.Text);
                cnx.Close();
                cnx.Dispose();
                this.Dispose();
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: Al obtener alguna de las configuraciones.\r\n\r\n" + error.Message, "Error");
                cnx.Dispose();
            }
        }
    protected void InsertKeyIntoConfNumTable(string confnum)
    {
        string strCon = "Data Source=(local);Initial Catalog=FlightDB;Integrated Security=True";
        SqlConnection objCon = new SqlConnection(strCon);

        try
        {
            objCon.ConnectionString = strCon;
            objCon.Open();
        }
        catch (Exception ex)
        {
            this.lblConnect.Text = "Unable to connect to database.";
        }

        if (objCon.State == System.Data.ConnectionState.Open)
        {
            string sql = "INSERT INTO flightconfirmation (confnum) VALUES ('" + confnum + "')";
            SqlCommand cmd = new SqlCommand(sql, objCon);
            cmd.ExecuteNonQuery();

            objCon.Close();
            objCon.Dispose();
        }
        else
        {
            lblConnect.Text = "Unable to connect to database.";
            objCon.Close();
            objCon.Dispose();

        }

        objCon.Close();
        objCon.Dispose();
    }
        private void borraFalta(int fila, int columna)
        {
            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;
            fh = new Faltas.Core.FaltasHelper();
            fh.Command = cmd;
            Faltas.Core.Faltas falta = new Faltas.Core.Faltas();
            falta.idtrabajador = int.Parse(dgvFaltas.Rows[fila].Cells["idtrabajadorfalta"].Value.ToString());
            falta.fechainicio = periodoInicio.Date;
            falta.fechafin = periodoFin.Date;
            falta.fecha = DateTime.Parse(dgvFaltas.Columns[columna].Name.ToString());
            try
            {
                cnx.Open();
                fh.eliminaFaltaExistente(falta);
                cnx.Close();
                cnx.Dispose();
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: \r\n \r\n" + error.Message, "Error");
                cnx.Dispose();
            }

            //if (dgvFaltas.Columns[columna].Name == "falta"){}
        }
 /// <summary>
 /// 执行查询语句,返回SqlDataReader ( 注意:使用后一定要对SqlDataReader进行Close )
 /// </summary>
 /// <param name="strSQL">查询语句</param>
 /// <returns>SqlDataReader</returns>
 public static SqlDataReader ExecuteReader(string SQLString,params SqlParameter[] cmdParms)
 {
     SqlConnection connection = new SqlConnection(connectionString);
     SqlCommand cmd = new SqlCommand();
     try
     {
         PrepareCommand(cmd, connection, null,SQLString, cmdParms);
         SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
         cmd.Parameters.Clear();
         connection.Close();
         connection.Dispose();
         return myReader;
     }
     catch(System.Data.SqlClient.SqlException e)
     {
         connection.Close();
         connection.Dispose();
         throw new Exception(e.Message);
     }
     //			finally
     //			{
     //				cmd.Dispose();
     //				connection.Close();
     //			}
 }
Example #14
0
    private void LoadDateTime()
    {
        string strcon = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ToString();
        bool functionReturnValue = false;
        SqlCommand CmdCustomer = new SqlCommand();
        string QryStr = "";
        System.Data.SqlClient.SqlCommand UpdateCmd = null;
        int Status = 0;
        conn = new SqlConnection(strcon);
        conn.Open();
        CmdCustomer = new SqlCommand("spSearch", conn);
        CmdCustomer.CommandType = CommandType.StoredProcedure;

        CmdCustomer.Parameters.AddWithValue("@ColumnsTxt", "ModDateTime");
        CmdCustomer.Parameters.AddWithValue("@TableName", "InternalMemo");
        CmdCustomer.Parameters.AddWithValue("@flg", 1);

        CmdCustomer.Parameters.Add("@ReturnVal", SqlDbType.VarChar, 10).Direction = ParameterDirection.ReturnValue;

        try
        {
            string st1 = CmdCustomer.ExecuteScalar().ToString();
            lblDateTime.Text = st1;
            if (CmdCustomer.Parameters["@ReturnVal"].Value.ToString() == "1")
            {

                CmdCustomer.Dispose();
                Session["SaveFlag"] = 0;
                functionReturnValue = true;
            }
            else
            {
                CmdCustomer.Dispose();
                Session["SaveFlag"] = 0;
                functionReturnValue = false;
            }
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
                conn.Dispose();
            }
        }
        catch (Exception ex)
        {

            functionReturnValue = false;
        }
        finally
        {
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
                conn.Dispose();
            }
        }
    }
        public List<ActividadBE> GetActividades(string periodo)
        {
            SqlConnection Conn = null;
            String sCadenaConeccion;
            String sqlUsuarioObtener;
            SqlCommand cmdUsuarioObtener = null;
            SqlDataReader drUsuarioObtener;
            SqlParameter prmCiclo;

            try
            {
                sCadenaConeccion = Settings.Default.csDesarrollo;
                Conn = new SqlConnection(sCadenaConeccion);
                sqlUsuarioObtener = "usps_Actividad";
                cmdUsuarioObtener = Conn.CreateCommand();
                cmdUsuarioObtener.CommandText = sqlUsuarioObtener;
                cmdUsuarioObtener.CommandType = CommandType.StoredProcedure;

                prmCiclo = cmdUsuarioObtener.CreateParameter();
                prmCiclo.ParameterName = "@ciclo";
                prmCiclo.SqlDbType = SqlDbType.VarChar;
                prmCiclo.Value = periodo;

                cmdUsuarioObtener.Parameters.Add(prmCiclo);
                cmdUsuarioObtener.Connection.Open();
                drUsuarioObtener = cmdUsuarioObtener.ExecuteReader();

                ActividadBE actividad;
                List<ActividadBE> lstactividad = new List<ActividadBE>();

                while (drUsuarioObtener.Read())
                {
                    actividad = new ActividadBE();
                    actividad.id = drUsuarioObtener.GetInt32(drUsuarioObtener.GetOrdinal("id"));
                    actividad.mensaje = drUsuarioObtener.GetString(drUsuarioObtener.GetOrdinal("mensaje"));
                    actividad.fecha = drUsuarioObtener.GetString(drUsuarioObtener.GetOrdinal("fecha"));
                    actividad.titulo = drUsuarioObtener.GetString(drUsuarioObtener.GetOrdinal("titulo"));
                    actividad.ciclo = drUsuarioObtener.GetString(drUsuarioObtener.GetOrdinal("ciclo"));
                    lstactividad.Add(actividad);

                }

                cmdUsuarioObtener.Connection.Close();
                cmdUsuarioObtener.Dispose();
                Conn.Dispose();

                return lstactividad;

            }
            catch (Exception ex)
            {
                cmdUsuarioObtener.Dispose();
                Conn.Dispose();
                throw;
            }
        }
        public decimal Peso_Uno(string codigo)
        {
            SqlConnection Conn = null;
            String sCadenaConeccion;
            String sqlUsuarioObtener;
            SqlCommand cmdUsuarioObtener = null;
            SqlDataReader drUsuarioObtener;
            SqlParameter prmCodAlumno;

            try
            {

                PromedioxCursoBE Promedio;

                sCadenaConeccion = Settings.Default.csDesarrollo;
                Conn = new SqlConnection(sCadenaConeccion);
                sqlUsuarioObtener = "usps_PesoCurso";
                cmdUsuarioObtener = Conn.CreateCommand();
                cmdUsuarioObtener.CommandText = sqlUsuarioObtener;
                cmdUsuarioObtener.CommandType = CommandType.StoredProcedure;

                prmCodAlumno = cmdUsuarioObtener.CreateParameter();
                prmCodAlumno.ParameterName = "@Curso_id";
                prmCodAlumno.SqlDbType = SqlDbType.Int;
                prmCodAlumno.Value = Convert.ToInt32(codigo);

                cmdUsuarioObtener.Parameters.Add(prmCodAlumno);
                cmdUsuarioObtener.Connection.Open();
                drUsuarioObtener = cmdUsuarioObtener.ExecuteReader();
                Promedio = new PromedioxCursoBE();

                decimal promedio = 0;

                while (drUsuarioObtener.Read())
                {
                    promedio = Math.Round(drUsuarioObtener.GetDecimal(drUsuarioObtener.GetOrdinal("promedio")), 2);

                }

                cmdUsuarioObtener.Connection.Close();
                cmdUsuarioObtener.Dispose();
                Conn.Dispose();

                return promedio;

            }
            catch (Exception ex)
            {
                cmdUsuarioObtener.Dispose();
                Conn.Dispose();
                throw;
            }
        }
Example #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["VC"] != null)
            {
                string VC = Request.Cookies["VC"].Values["VC"];
                Classes.LoginSession ls = new Classes.LoginSession();
                int UserId = ls.getUserId(VC);
                if (UserId == 0)
                {
                    Response.Redirect("~/Login/Requests");
                }
                else
                {
                    Session["UserId"] = UserId.ToString();
                }
            }
            else
            {
                Response.Redirect("~/Login/Requests");
            }

            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ProfilesConnectionString"].ConnectionString);
            SqlCommand sqlCmd = new SqlCommand("sp_requestsAllRead", sqlConn);

            try
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = Convert.ToInt32(Session["UserId"]);

                sqlConn.Open();
                sqlCmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {

            }
            finally
            {
                sqlConn.Close();
                sqlCmd.Dispose();
                sqlConn.Dispose();
            }

            sqlCmd.Dispose();
            sqlConn.Dispose();

            if (GridViewFriends.Rows.Count == 0)
            {
                LabelFriendsNoRecord.Visible = true;
            }
        }
Example #18
0
        public List<PeriodoBE> GetPeriodo()
        {
            SqlConnection Conn = null;
            String sCadenaConeccion;
            String sqlUsuarioObtener;
            SqlCommand cmdUsuarioObtener = null;
            SqlDataReader drUsuarioObtener;

            try
            {

                List<PeriodoBE> Periodos = new List<PeriodoBE>();
                PeriodoBE Periodo;

                sCadenaConeccion = Properties.Settings.Default.csDesarrollo;
                Conn = new SqlConnection(sCadenaConeccion);
                sqlUsuarioObtener = "UMOBILE.sp_Periodo";
                cmdUsuarioObtener = Conn.CreateCommand();
                cmdUsuarioObtener.CommandText = sqlUsuarioObtener;
                cmdUsuarioObtener.CommandType = CommandType.StoredProcedure;

                cmdUsuarioObtener.Connection.Open();
                drUsuarioObtener = cmdUsuarioObtener.ExecuteReader();

                while (drUsuarioObtener.Read())
                {
                    Periodo = new PeriodoBE();
                    Periodo.Id = drUsuarioObtener.GetInt32(drUsuarioObtener.GetOrdinal("id"));
                    Periodo.Periodo = drUsuarioObtener.GetString(drUsuarioObtener.GetOrdinal("periodo"));
                    Periodo.Inicio = drUsuarioObtener.GetString(drUsuarioObtener.GetOrdinal("inicio"));
                    Periodo.Fin = drUsuarioObtener.GetString(drUsuarioObtener.GetOrdinal("fin"));

                    Periodos.Add(Periodo);
                }

                cmdUsuarioObtener.Connection.Close();
                cmdUsuarioObtener.Dispose();
                Conn.Dispose();

                return Periodos;

            }
            catch (Exception ex)
            {
                cmdUsuarioObtener.Dispose();
                Conn.Dispose();
                throw;
            }
        }
Example #19
0
 protected void ButNewDept_Click(object sender, System.EventArgs e)
 {
     if (txtTestTypeName.Text.Trim()=="")
     {
         this.RegisterStartupScript("newWindow","<script language='javascript'>alert('�������Ʋ���Ϊ�գ�')</script>");
         return;
     }
     string strTmp=ObjFun.GetValues("select TestTypeName from TestTypeInfo where TestTypeName='"+ObjFun.getStr(ObjFun.CheckString(txtTestTypeName.Text.Trim()),20)+"'","TestTypeName");
     if (strTmp=="")
     {
         string strConn=ConfigurationSettings.AppSettings["strConn"];
         SqlConnection SqlConn=new SqlConnection(strConn);
         SqlCommand SqlCmd=new SqlCommand("Insert into TestTypeInfo(TestTypeName,BaseTestType) values('"+ObjFun.getStr(ObjFun.CheckString(txtTestTypeName.Text.Trim()),20)+"','"+DDLBaseTestType.SelectedItem.Value+"')",SqlConn);
         SqlConn.Open();
         SqlCmd.ExecuteNonQuery();
         SqlConn.Close();
         SqlConn.Dispose();
         this.RegisterStartupScript("newWindow","<script language='javascript'>alert('����������Ƴɹ���')</script>");
     }
     else
     {
         this.RegisterStartupScript("newWindow","<script language='javascript'>alert('�����������Ѿ����ڣ�')</script>");
         return;
     }
     txtTestTypeName.Text="";
     ShowData(strSql);
 }
Example #20
0
        public static void DeleteOneDto(string table, string strwhere)
        {
            SqlParameter[] arParames = new SqlParameter[2];
            arParames[0] = new SqlParameter("@table ", SqlDbType.VarChar, 200);
            arParames[0].Value = table;

            arParames[1] = new SqlParameter("@Where ", SqlDbType.VarChar, 8000);
            arParames[1].Value = strwhere;
            SqlConnection myconn = new SqlConnection(CommonDal.ConnectionString);
            try
            {
                SqlHelper.ExecuteNonQuery(myconn, CommandType.StoredProcedure, "deleteModelByWhere", arParames);

            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {

                myconn.Close();
                myconn.Dispose();
            }
        }
Example #21
0
    protected void cmdAdd_Click1(object sender, EventArgs e)
    {
        try
        {
            ClearFields(1);
            ClearFields(2);
            // ClearFields(3);
            Session["SaveFlag"] = 1;
            conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ToString());
            conn.Open();
            Obj.FillComboWithSelect(this.cboCity, "spsearch @ColumnsTxt = 'CityID,Cityname + '' - ''+Countryname CtName',@SortColumn='CtName',@TableName='citymaster,countrymaster',@SearchTxt='citymaster.countryid=countrymaster.countryid'", "CTNAME", "CityID", conn);
            //Obj1.FillComboWithSelect(this.suplytypecombo, "spsearch @ColumnsTxt = 'STID,STName',@SortColumn='STName',@TableName='supptypemaster'", "STName", "STID", conn);
            Obj.FillComboWithSelect(this.cboCusttype, "spsearch @ColumnsTxt = 'CTID,CTName',@SortColumn='CTName',@TableName='CustTypeMaster'", "CTName", "CTID", conn);
            Obj.FillComboWithSelect(this.cboCurrency, "spsearch @ColumnsTxt = 'CurID,CurName',@SortColumn='CurName',@TableName='currencymaster'", "CurName", "CurID", conn);
            Obj.FillComboWithSelect(this.cboSaleMangrId, "spsearch @ColumnsTxt = 'UserId,UserName',@SortColumn='UserName',@TableName='UserMaster'", "UserName", "UserId", conn);
            Obj.FillComboWithSelect(this.cboInhouseConId, "spsearch @ColumnsTxt = 'UserId,UserName',@SortColumn='UserName',@TableName='UserMaster'", "UserName", "UserId", conn);

            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
                conn.Dispose();
            }

            ClientScript.RegisterStartupScript(GetType(), "key", "pop('pop1','2');", true);

            //Me.txtGraceTillDate.SelectedDate = Obj.GetDateFormat(CDate(Now()))

        }
        catch (Exception ex)
        {
        }
    }
Example #22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string fileext = System.IO.Path.GetExtension(FileUpload1.FileName);

                if (fileext == ".jpg" || fileext == ".gif" || fileext == ".png")
                {
                    int Size = FileUpload1.PostedFile.ContentLength;
                    FileUpload1.SaveAs(Server.MapPath("TravelImages") + "\\" + FileUpload1.FileName);
                    string FileName = System.IO.Path.GetFileName(FileUpload1.FileName);
                    string Folder = "~/First system/Image/";
                    string FileUrl = Folder + FileName;

                    SqlConnection conn = new SqlConnection("server=172.16.101.46;database=SysAuction;uid=sa;pwd=zjj1024455257");
                    conn.Open();
                    string myinsert = "update [User]  set headpicture ='Image/headpic.jpg' where Username='"+Session["Username"]+"'";
                    SqlCommand mycom = new SqlCommand(myinsert, conn);
                    mycom.ExecuteNonQuery();
                    conn.Close();
                    conn.Dispose();
                }
            }
            catch
            {
            }
        }
Example #23
0
        public static string GetProcessId(ref string ProcessId, string TenderNumber)
        {
            SqlConnection sqlConn = new SqlConnection();  //defines database connection
            SqlCommand sqlCmd = new SqlCommand();  //defines what to do
            SqlDataAdapter sqlAdap = new SqlDataAdapter();

            try
            {
                sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["AMS_MasterConnectionString"].ToString();
                sqlConn.Open();

                sqlCmd.CommandText = "SELECT  [TH_ProcessID] FROM [AMS_Master].[dbo].[Tender_Header] H WHERE [TH_NoTender] = '" + TenderNumber + "'";
                sqlCmd.CommandType = CommandType.Text;
                sqlCmd.Connection = sqlConn;

                ProcessId = sqlCmd.ExecuteScalar().ToString();
                return string.Empty;
            }
            catch (Exception err)
            {
                return err.Message;
            }
            finally
            { sqlConn.Close(); sqlConn.Dispose(); sqlAdap.Dispose(); }
        }
 //  To Change status of 'Group' record of specific GroupId from database by stored procedure
 public int ChangeGroupStatus(int GroupId, int LoggedInUser, string returnmsg, bool IsActive)
 {
     SqlConnection Conn = new SqlConnection(ConnStr);
         Conn.Open();
         //  'uspUpdateGroupStatus' stored procedure is used to Chnage Status of record in Group table
         SqlCommand DCmd = new SqlCommand("uspUpdateGroupStatus", Conn);
         DCmd.CommandType = CommandType.StoredProcedure;
         DCmd.Parameters.AddWithValue("@GroupId", GroupId);
         DCmd.Parameters.AddWithValue("@LoggedInUser", LoggedInUser);
         DCmd.Parameters.AddWithValue("@IsActive", IsActive);
         DCmd.Parameters.AddWithValue("@RetMsg", returnmsg);
         try
         {
             return DCmd.ExecuteNonQuery();
         }
         catch
         {
             throw;
         }
         finally
         {
             DCmd.Dispose();
             Conn.Close();
             Conn.Dispose();
         }
 }
Example #25
0
    protected void btnOpen_Click(object sender, EventArgs e)
    {
        string dbName = tbDBName.Text;

        SqlConnection con = new SqlConnection();
        con.StateChange += con_StateChange;
        con.InfoMessage += con_InfoMessage;

        try
        {
            con.ConnectionString = ConfigurationManager.ConnectionStrings[dbName].ConnectionString;
            con.Open();
        }
        catch (SqlException ex)
        {
            lbLog.Items.Add(ex.Message);
        }
        catch (Exception ex)
        {
            lbLog.Items.Add(ex.Message);
        }
        finally
        {
            con.Dispose();
        }

    }
        public void DeleteAdmin(String id, ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            try
            {
                var adapter = new SqlDataAdapter(DeleteAdminProcedure, conn)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@admin_id", SqlDbType.VarChar, 20));

                adapter.SelectCommand.Parameters["@admin_id"].Value = id;

                var dataSet = new DataSet();
                adapter.Fill(dataSet);
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }
        }
 //  To insert 'SubMenu' record in database by stored procedure
 public int InsertSubMenu(int MenuId, string SubMenuName, string SubMenuDesc, string SubMenuURL,int IsActive,int LoggedInUser, string RetMsg)
 {
     SqlConnection Conn = new SqlConnection(ConnString);
     Conn.Open();
     //  'uspInsertSubMenu' stored procedure is used to insert record in SubMenu table
     SqlCommand Cmd = new SqlCommand("uspInsertSubMenu", Conn);
     Cmd.CommandType = CommandType.StoredProcedure;
     try
     {
         Cmd.Parameters.AddWithValue("@MenuID", MenuId);
         Cmd.Parameters.AddWithValue("@SubMenuName", SubMenuName);
         Cmd.Parameters.AddWithValue("@SubMenuDescription", SubMenuDesc);
         Cmd.Parameters.AddWithValue("@SubMenuURL", SubMenuURL);
         Cmd.Parameters.AddWithValue("@IsActive", IsActive);
         Cmd.Parameters.AddWithValue("@LoggedInUser", LoggedInUser);
         Cmd.Parameters.AddWithValue("@RetMsg", RetMsg);
         return Cmd.ExecuteNonQuery();
     }
     catch
     {
         throw;
     }
     finally
     {
         Cmd.Dispose();
         Conn.Close();
         Conn.Dispose();
     }
 }
Example #28
0
 /// <summary>
 /// 查询操作方法
 /// </summary>
 /// <param name="sql">执行的sql语句</param>
 /// <param name="cmdType">sql语句类型</param>
 /// <param name="paras">传入的参数</param>
 /// <returns>返回执行结果的首行首列</returns>
 public static object ExecuteScalar(string sql, CommandType cmdType, params SqlParameter[] paras)
 {
     using (SqlConnection conn = new SqlConnection(serverPath))
     {
         using (SqlCommand cmd = new SqlCommand(sql, conn))
         {
             if (paras != null)
             {
                 cmd.Parameters.AddRange(paras);
             }
             cmd.CommandType = cmdType;
             try
             {
                 conn.Open();
                 return cmd.ExecuteScalar();
             }
             catch (Exception ex)
             {
                 conn.Close();
                 conn.Dispose();
                 throw ex;
             }
         }
     }
 }
Example #29
0
        public ActionResult ClassExistProduct(int class_appser)
        {
            string msg;

            // 1. 資料庫連線
            SqlConnection cn = new SqlConnection(_connectionString);

            // 2. SQL 指令
            string sql = "select COUNT(*) from product_class a join Product b on a.app_ser=b.prod_class_id where [email protected]";

            cn.Open();
            SqlCommand comm = new SqlCommand(sql, cn);
            comm.Parameters.Clear();
            comm.Parameters.AddWithValue("@id", class_appser);
            if ((int)comm.ExecuteScalar() > 0)
            {
                msg = "Exist";
            }
            else
            {
                msg = "OK";
            }

            cn.Close();
            cn.Dispose();

            var result = new
            {
                message = msg
            };
            return Json(result, JsonRequestBehavior.AllowGet);
            //string obj_json = JsonConvert.SerializeObject(result);
            //return Content(obj_json, "application/json");
        }
Example #30
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //check login status
        CheckLogin cl = new CheckLogin();
        bool LoginStatus = cl.checkLogin(Convert.ToInt32(Session["UserId"]));
        if (!LoginStatus)
        {
            Response.Redirect("Login.aspx?Page=Requests");
        }

        SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ShopConnectionString"].ConnectionString);
        SqlCommand sqlCmd = new SqlCommand("sp_requestsAllRead", sqlConn);
        sqlCmd.CommandType = CommandType.StoredProcedure;
        sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = Convert.ToInt32(Session["UserId"]);

        sqlConn.Open();
        sqlCmd.ExecuteNonQuery();

        sqlCmd.Dispose();
        sqlConn.Dispose();

        if (GridViewFriends.Rows.Count == 0)
        {
            LabelFriendsNoRecord.Visible = true;
        }
    }