示例#1
0
        public int GetHistoryid(int DefectID)
        {
            //Define the Command Object
            int    ID      = 0;
            string defect1 = "";
            //IDDefect = Convert.ToInt32(DefectID);
            TdConnection con = new TdConnection(strConnString);

            Teradata.Client.Provider.TdCommand AdvancedDefectSearch =
                new Teradata.Client.Provider.TdCommand("Select max(defecthistid)+ 1 as test from  coebatch.tbl_Defect_history where  DefectID = " + DefectID + ";", con);

            try
            {
                //Open the Connection  to connect to the database
                con.Open();

                //Execute the Query
                //AdvancedDefectSearch.ExecuteNonQuery();
                TdDataReader r = AdvancedDefectSearch.ExecuteReader();
                if (r.Read())
                {
                    defect1 = r["test"].ToString();
                }
                r.Close();

                if (defect1 == "")
                {
                    con.Close();
                    return(ID);
                }
                else
                {
                    ID = Convert.ToInt32(defect1);
                    return(ID);
                }


                // nextDefectId = (int)cmdNewDefect.ExecuteScalar();
            }
            catch (TdException ex)
            {
                return(ID);

                throw ex;
            }
            finally
            {
                //Close the Connection from the Database
                con.Close();
            }
        }
示例#2
0
        public int GetDefectcount()
        {
            string       query = "";
            int          ID    = 0;
            TdCommand    cmd   = new TdCommand(query);
            TdConnection con   = new TdConnection(strConnString);

            Teradata.Client.Provider.TdCommand AdvancedDefectSearch =
                new Teradata.Client.Provider.TdCommand("select count(*) as test  from coebatch.tbl_defect ", con);

            try
            {
                //Open the Connection  to connect to the database
                con.Open();

                //Execute the Query
                //AdvancedDefectSearch.ExecuteNonQuery();
                TdDataReader r = AdvancedDefectSearch.ExecuteReader();
                if (r.Read())
                {
                    query = r["test"].ToString();
                }
                r.Close();

                if (query == "")
                {
                    con.Close();
                    return(ID);
                }
                else
                {
                    ID = Convert.ToInt32(query);
                }


                // nextDefectId = (int)cmdNewDefect.ExecuteScalar();
            }
            catch (TdException ex)
            {
                return(ID);
            }
            finally
            {
                //Close the Connection from the Database
                con.Close();
            }
            return(ID);
        }
示例#3
0
        public int GetNextDefectID()
        {
            TdConnection con = new TdConnection(strConnString);

            Teradata.Client.Provider.TdCommand cmdNewDefect = new Teradata.Client.Provider.TdCommand("SELECT MAX(DefectId)+1 as test FROM coebatch.tbl_Defect", con);
            int    nextDefectId = 0;
            string defectid     = "";


            try
            {
                //Open the Connection  to connect to the database
                con.Open();
                //Execute the Query
                //nextDefectId = (int)cmdNewDefect.ExecuteScalar();
                TdDataReader r = cmdNewDefect.ExecuteReader();
                if (r.Read())
                {
                    defectid = r["test"].ToString();
                }
                r.Close();

                // nextDefectId = cmdNewDefect.ExecuteScalar();
                if (defectid == "")
                {
                    nextDefectId = 1;
                }
                else
                {
                    nextDefectId = Convert.ToInt32(defectid);
                }
            }
            catch (Teradata.Client.Provider.TdException ex)
            {
                //Throw the exception to calling environment
                throw ex;
            }
            finally
            {
                //Close the Connection from the Database
                con.Close();
            }
            return(nextDefectId);
        }