예제 #1
0
        /// <summary>
        /// Select文を発行する
        /// </summary>
        /// <param name="sql">SQL文</param>
        /// <param name="tableName">検索結果のテーブル名</param>
        /// <returns>検索結果データテーブル</returns>
        public DataTable SelectSql(string sql, string tableName)
        {
            NpgsqlDataAdapter adapter = null;

            try
            {
                using (NpgsqlCommand cmd = this.CreateCommand())
                {
                    cmd.CommandText = sql;
                    adapter         = new NpgsqlDataAdapter(sql, this._ConnString);
                    DataSet dts = new DataSet();
                    adapter.SelectCommand = cmd;
                    adapter.Fill(dts, tableName);
                    if (!dts.Tables.Contains(tableName))
                    {
                        return(null);
                    }
                    adapter.Dispose();
                    return(dts.Tables[tableName]);
                }
            }
            catch (Exception ex)
            {
                this._InnerException = ex;
                throw ex;
            }
            finally
            {
                if (adapter != null)
                {
                    adapter.Dispose();
                }
            }
        }
예제 #2
0
        public List <Enterprise> readAll(NpgsqlConnection conn)
        {
            List <Enterprise> result = new List <Enterprise>();

            string sql = "SELECT distinct id_empresa, empresa " +
                         "FROM dim_sellers";

            DataTable         dt = new DataTable();
            NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);

            da.Fill(dt);

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Enterprise enterprise = new Enterprise();

                    enterprise.Id     = long.Parse(dt.Rows[i][0].ToString());
                    enterprise.Nombre = dt.Rows[i][1].ToString();

                    result.Add(enterprise);
                }
            }

            da.Dispose();
            listEnterprises = result;
            return(result);
        }
        void listele(string query)
        {
            try
            {
                //Eğer bağlantı yoksa bağlantıyı aç

                if (baglanti.State == ConnectionState.Open)
                {
                    //MessageBox.Show("Açık");
                }
                else
                {
                    //MessageBox.Show("Kapalı");
                    //baglanti.Open();
                }
                tablo.Clear();
                baglanti.Open();
                /// MessageBox.Show("Bağlantı Başarılı");
                NpgsqlDataAdapter adtr = new NpgsqlDataAdapter("select *from urunler", baglanti);

                adtr.Fill(tablo);
                dataGridView1.DataSource = tablo;
                adtr.Dispose();
                baglanti.Close();
            }

            catch (Exception Hata)
            {
                MessageBox.Show("Hata: " + Hata.Message);
            }
        }//Listele Bitiş
예제 #4
0
 /// <summary>
 /// 查询方法  返回DataTable
 /// </summary>
 /// <param name="conStr"></param>
 /// <param name="sql"></param>
 /// <param name="list"></param>
 /// <returns></returns>
 internal async static Task <DataTable> QueryDataTable(string conStr, string sql, List <NpgsqlParameter> list = null)
 {
     return(await Task.Run(() =>
     {
         DataTable dt = new DataTable();
         using (PostgreSqlHelper.con = PostgreSqlHelper.NewConnectionMethod(conStr))
         {
             var sda = new NpgsqlDataAdapter(sql, PostgreSqlHelper.con);
             if (list != null)
             {
                 foreach (NpgsqlParameter item in list)
                 {
                     sda.SelectCommand.Parameters.Add(item);
                 }
             }
             try
             {
                 sda.Fill(dt);
                 sda.Dispose();
                 PostgreSqlHelper.con.Close();
                 PostgreSqlHelper.con.Dispose();
             }
             catch (Exception e)
             {
                 PostgreSqlHelper.con.Close();
                 PostgreSqlHelper.con.Dispose();
                 throw e;
             }
             return dt;
         }
     }));
 }
예제 #5
0
        public DataTable getMenuItems(int id_rol)
        {
            NpgsqlConnection  conexion    = null;
            NpgsqlCommand     cmd         = null;
            DataTable         dtMenuItems = new DataTable();
            NpgsqlTransaction tran        = null;
            NpgsqlDataAdapter sda         = null;

            try
            {
                conexion = Conexion.getInstance().ConexionDB();
                conexion.Open();
                tran            = conexion.BeginTransaction();
                cmd             = new NpgsqlCommand("logueo.spgetmenuitem", conexion);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("parm_idrol", id_rol);
                sda = new NpgsqlDataAdapter(cmd);
                sda.Fill(dtMenuItems);
                cmd.Dispose();
                sda.Dispose();
            }
            catch (Exception e)
            {
                dtMenuItems = null;
                throw e;
            }
            finally
            {
                tran.Commit();
                conexion.Close();
            }
            return(dtMenuItems);
        }
예제 #6
0
        public void getComboBoxData(string sql, ref ComboBox cmb)
        {
            NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
            NpgsqlCommand     command;
            DataSet           ds = new DataSet();

            try
            {
                connection = new NpgsqlConnection(conStringBoxidDb);
                connection.Open();
                command = new NpgsqlCommand(sql, connection);
                adapter.SelectCommand = command;
                adapter.Fill(ds);
                adapter.Dispose();
                command.Dispose();
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    cmb.Items.Add(row[0].ToString());
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can not open connection ! ");
                connection.Close();
            }
        }
예제 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            sql = "Select * From receipt";
            NpgsqlDataAdapter dat = new NpgsqlDataAdapter(sql, WebForm3.conn);
            DataSet           ds  = new DataSet();

            dat.Fill(ds);
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();

            dat.Dispose();
            Label1.Text = " Enter name of user and number of receipt which you whant to edit, please";
            Label2.Text = "Name: ";
            TextBox2.Focus();
            RequiredFieldValidator2.ControlToValidate = "TextBox2";
            RequiredFieldValidator2.ErrorMessage      = "* fill Name";

            Label3.Text = "Number: ";
            TextBox3.Focus();
            RequiredFieldValidator3.ControlToValidate = "TextBox3";
            RequiredFieldValidator3.ErrorMessage      = "* fill Number";
            Button1.Text     = "Edit";
            Button2.Visible  = false;
            Label4.Visible   = Label5.Visible = Label6.Visible = Label7.Visible = Label8.Visible = Label9.Visible = false;
            TextBox5.Visible = TextBox6.Visible = TextBox7.Visible = TextBox8.Visible = TextBox9.Visible = false;
            RequiredFieldValidator5.Visible = RequiredFieldValidator6.Visible = RequiredFieldValidator7.Visible = RequiredFieldValidator8.Visible = RequiredFieldValidator9.Visible = false;
        }
예제 #8
0
 public async Task <DataTable> QueryDataTable(string connectionString, string sqlString, List <IDbDataParameter> parameters = null)
 {
     return(await Task.Run(() =>
     {
         DataTable dt = new DataTable();
         this.NewConnectionMethod(connectionString);
         using (this._Con)
             using (NpgsqlDataAdapter sda = new NpgsqlDataAdapter(sqlString, this._Con))
             {
                 if (parameters != null)
                 {
                     foreach (NpgsqlParameter item in parameters)
                     {
                         sda.SelectCommand.Parameters.Add(item);
                     }
                 }
                 try
                 {
                     sda.Fill(dt);
                     sda.Dispose();
                 }
                 catch (Exception e)
                 {
                     throw e;
                 }
                 return dt;
             }
     }));
 }
예제 #9
0
        private void cmdOk_Click(object sender, EventArgs e)
        {
            try
            {
                rptCarte          rpt = new rptCarte();
                NpgsqlCommand     cmd = new NpgsqlCommand(@"select numeroNational,numero,nom,postnom,prenom,sexe,etativil,datenaissance date,avenueVillage.designation as avenuevillage,quartierLocalite.designation as quartierLocalite,
	                                                communeChefferieSecteur.designation as communeChefferieSecteur,villeTerritoire.designation as villeTerritoire,parametreProvince.designation as province,photo.photo as photo
	                                                FROM parametreProvince,personne
	                                                INNER JOIN avenueVillage ON avenueVillage.id=personne.id_avenueVillage 
	                                                INNER JOIN quartierLocalite ON quartierLocalite.id=avenueVillage.id_quartierLocalite
	                                                INNER JOIN communeChefferieSecteur ON communeChefferieSecteur.id=quartierLocalite.id_communeChefferieSecteur
	                                                INNER JOIN villeTerritoire ON villeTerritoire.id=communeChefferieSecteur.id_villeTerritoire
	                                                INNER JOIN photo ON photo.id_personne=personne.id
	                                                WHERE personne.id="     + p.Id + "", Factory.Instance.connect());
                NpgsqlDataAdapter da  = new NpgsqlDataAdapter(cmd);
                DtsTauxMortalite  ds  = new DtsTauxMortalite();
                da.Fill(ds, "doc");
                rpt.SetDataSource(ds.Tables["doc"]);
                crvCarte.ReportSource = rpt;
                crvCarte.Refresh();
                da.Dispose();
                ds.Dispose();
                cmd.Dispose();
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Erreur de l'afichage du rapport", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
예제 #10
0
        public override DataTable Query(string cmdText, CommandType cmdType, DbParameter[] parameters)
        {
            DataTable rtDt = new DataTable();

            try
            {
                using (NpgsqlCommand cmd = new NpgsqlCommand(cmdText, (NpgsqlConnection)this.Connection))
                {
                    cmd.CommandType = cmdType;
                    if (parameters != null)
                    {
                        cmd.Parameters.AddRange(parameters);
                    }
                    cmd.CommandTimeout = 0;

                    NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd);
                    this.OpenConnection();
                    da.Fill(rtDt);
                    da.Dispose();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                this.CloseConnection();
            }

            return(rtDt);
        }
예제 #11
0
        public void getAutoCompleteData(string sql, ref TextBox txt)
        {
            txt.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
            txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
            AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection();

            NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
            NpgsqlCommand     command;
            DataSet           ds = new DataSet();

            try
            {
                connection = new NpgsqlConnection(conStringIpqcDbP4);
                connection.Open();
                command = new NpgsqlCommand(sql, connection);
                adapter.SelectCommand = command;
                adapter.Fill(ds);
                adapter.Dispose();
                command.Dispose();
                connection.Close();
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    DataCollection.Add(row[0].ToString());
                }
                txt.AutoCompleteCustomSource = DataCollection;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Database Responce", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                connection.Close();
            }
        }
예제 #12
0
        public DataTable selectData(NpgsqlConnection con, String sql)
        {
            DataTable toReturn = new DataTable();

            NpgsqlCommand comMainhis = new NpgsqlCommand();

            comMainhis.CommandText = sql;
            comMainhis.CommandType = CommandType.Text;
            comMainhis.Connection  = con;
            NpgsqlDataAdapter adapMainhis = new NpgsqlDataAdapter(comMainhis);

            try
            {
                //new LogWriter("e", "ConnectDB selectData con.ConnectionString " + con.ConnectionString);

                con.Open();
                adapMainhis.Fill(toReturn);
                //return toReturn;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                con.Close();
                comMainhis.Dispose();
                adapMainhis.Dispose();
            }
            return(toReturn);
        }
        /// <summary>
        /// Execue sql Command With Parameter
        /// </summary>
        /// <param name="StoreProCommand">SQL command String</param>
        /// <param name="ParameterIn">Parameter of Input</param>
        /// <param name="Timeout">[option] timeout of database connect(seconds)</param>
        /// <returns>
        /// dataset value
        /// </returns>
        public DataSet ExecueStoreProCommand(String StoreProCommand,
                                             ParameterClass[] ParameterIn, Int32 Timeout = 30)
        {
            if (conn == null)
            {
                throw new Exception("Connection has not initialize.");
            }

            if (conn.State != ConnectionState.Open)
            {
                throw new Exception("Connection has not opened.");
            }

            NpgsqlDataAdapter da = new NpgsqlDataAdapter(StoreProCommand, conn);

            da.SelectCommand.CommandTimeout = Timeout;
            da.SelectCommand.CommandType    = CommandType.StoredProcedure;

            //add parameter
            for (int number = 0; number < ParameterIn.Length; number++)
            {
                da.SelectCommand.Parameters.AddWithValue(ParameterIn[number].ParameterName, ParameterIn[number].Value);
            }

            DataSet ds = new DataSet();

            da.Fill(ds);
            da.Dispose();

            return(ds);
        }
예제 #14
0
        public List <Director> readAll(NpgsqlConnection conn)
        {
            List <Director> result = new List <Director>();

            string sql = "SELECT director_id, sms, director_name, email, cellphone, id_empresa " +
                         "FROM dim_directors where sms = true";

            DataTable         dt = new DataTable();
            NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);

            da.Fill(dt);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Director director = new Director();

                director.ID         = long.Parse(dt.Rows[i][0].ToString());
                director.SMS        = bool.Parse(dt.Rows[i][1].ToString());
                director.Name       = dt.Rows[i][2].ToString();
                director.Email      = dt.Rows[i][3].ToString();
                director.CellPhone  = dt.Rows[i][4].ToString();
                director.empresa_id = long.Parse(dt.Rows[i][5].ToString());

                result.Add(director);
            }

            da.Dispose();

            listDirectors = result;
            return(result);
        }
예제 #15
0
 private void cmdOk_Click(object sender, EventArgs e)
 {
     if (txtAnnee.Text != "")
     {
         annee = Convert.ToInt32(txtAnnee.Text);
         try
         {
             rptTautNatalite   rpt = new rptTautNatalite();
             NpgsqlCommand     cmd = new NpgsqlCommand(Factory1.Instance.fonctionCalculTauxNatalite(cboTypeEntite.Text, annee, id), Factory1.Instance.connect());
             NpgsqlDataAdapter da  = new NpgsqlDataAdapter(cmd);
             DtsTauxNatalite   ds  = new DtsTauxNatalite();
             da.Fill(ds, "doc");
             rpt.SetDataSource(ds.Tables["doc"]);
             crystalReportViewer1.ReportSource = rpt;
             crystalReportViewer1.Refresh();
             da.Dispose();
             ds.Dispose();
             cmd.Dispose();
         }
         catch (Exception exc)
         {
             MessageBox.Show(exc.Message, "Erreur de l'afichage du rapport", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     else
     {
         MessageBox.Show("vous devez specifier l'année dont vous voulez afficher le Taux de natalité", "Taux de natalité", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         txtAnnee.Focus();
     }
 }
예제 #16
0
파일: CustomerDAO.cs 프로젝트: bpun/AdoDemo
        public DataSet ExecuteDataset(string sql)
        {
            var ds = new DataSet();

            using (var con = new NpgsqlConnection(GetConnectionString()))
            {
                var cmd = new NpgsqlCommand(sql, con);
                cmd.CommandTimeout = GetCommandTimeOut();
                NpgsqlDataAdapter da;
                try
                {
                    da = new NpgsqlDataAdapter(cmd);
                    da.Fill(ds);
                    da.Dispose();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    da = null;
                    cmd.Dispose();
                }
                return(ds);
            }
        }
예제 #17
0
        public virtual bool GetSchema(string rstrSQL, string rstrTableName, DataSet rdatSet)
        {
            NpgsqlDataAdapter adapter = null;

            try
            {
                if (rdatSet == null)
                {
                    rdatSet = new DataSet();
                }
                using (NpgsqlCommand cmd = this.CreateCommand())
                {
                    cmd.CommandText       = rstrSQL;
                    cmd.CommandTimeout    = this._CommandTimeout;
                    adapter               = new NpgsqlDataAdapter(rstrSQL, this._ConnString);
                    adapter.SelectCommand = cmd;
                    adapter.FillSchema(rdatSet, SchemaType.Mapped, rstrTableName);
                }
                return(true);
            }
            catch (Exception ex)
            {
                this._InnerException = ex;
                throw ex;
            }
            finally
            {
                if (adapter != null)
                {
                    adapter.Dispose();
                }
            }
        }
예제 #18
0
        public DataTable GetDataTableTest(string query)
        {
            DataTable dataTable = new DataTable();

            try
            {
                using (NpgsqlConnection dbConnection = new NpgsqlConnection(connString))
                {
                    dbConnection.Open();

                    Console.WriteLine(dbConnection.ConnectionLifeTime);
                    Console.WriteLine(dbConnection.ConnectionTimeout);

                    using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter())
                    {
                        adapter.SelectCommand = new NpgsqlCommand(query, dbConnection);
                        adapter.Fill(dataTable);

                        adapter.Dispose();
                    }

                    dbConnection.Close();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
            }

            return(dataTable);
        }
예제 #19
0
        /// <summary>
        /// Get data list string
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="list"></param>
        public void getListString(string sql, ref List <string> list)
        {
            NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
            NpgsqlCommand     command;
            DataSet           ds = new DataSet();

            try
            {
                connection = new NpgsqlConnection(strConnection);
                connection.Open();
                command = new NpgsqlCommand(sql, connection);
                adapter.SelectCommand = command;
                adapter.Fill(ds);
                adapter.Dispose();
                command.Dispose();

                list.Clear();
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    list.Add(row[0].ToString());
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                connection.Close();
                throw new Exception(ex.Message);
            }
        }
예제 #20
0
        public void getComboBoxData(string sql, ref ComboBox cmb)
        {
            NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
            NpgsqlCommand     command;
            DataSet           ds = new DataSet();

            try
            {
                connection = new NpgsqlConnection(conStringIpqcDbP4);
                connection.Open();
                command = new NpgsqlCommand(sql, connection);
                adapter.SelectCommand = command;
                adapter.Fill(ds);
                adapter.Dispose();
                command.Dispose();

                cmb.Items.Clear();
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    cmb.Items.Add(row[0].ToString());
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Database Responce", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                connection.Close();
            }
        }
예제 #21
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            if (DropdowmList1.SelectedItem.Value == "name")
            {
                sql = " Select * from receipt order by name";
            }
            else if (DropdowmList1.SelectedItem.Value == "company")
            {
                sql = " Select * from receipt order by company";
            }
            //else if (DropdowmList1.SelectedItem.Value == "number")
            //{
            //    sql = " Select * from receipt order by number";
            //}
            else if (DropdowmList1.SelectedItem.Value == "arrears")
            {
                sql = " Select * from receipt order by arrears";
            }
            else if (DropdowmList1.SelectedItem.Value == "suma")
            {
                sql = " Select * from receipt order by suma";
            }


            NpgsqlDataAdapter dat = new NpgsqlDataAdapter(sql, WebForm3.conn);
            DataSet           ds  = new DataSet();

            dat.Fill(ds);
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
            dat.Dispose();
        }
예제 #22
0
        /// <summary>
        /// Get data into autocomplete text box
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="txt"></param>
        public void getAutoCompleteData(string sql, ref TextBox txt)
        {
            txt.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
            txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
            AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection();

            NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
            NpgsqlCommand     command;
            DataSet           ds = new DataSet();

            try
            {
                connection = new NpgsqlConnection(strConnection);
                connection.Open();
                command = new NpgsqlCommand(sql, connection);
                adapter.SelectCommand = command;
                adapter.Fill(ds);
                adapter.Dispose();
                command.Dispose();
                connection.Close();
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    DataCollection.Add(row[0].ToString());
                }
                txt.AutoCompleteCustomSource = DataCollection;
            }
            catch (Exception ex)
            {
                connection.Close();
                throw new Exception(ex.Message);
            }
        }
예제 #23
0
        // 根据SQL查询并用记录集填充DataSet
        public static bool FillDataset(string sql, DataSet ds, string tablename)
        {
            bool              bret = false;
            NpgsqlConnection  conn = null;
            NpgsqlDataAdapter da   = null;

            try
            {
                conn = new NpgsqlConnection(CONNECTIONSTR);
                da   = new NpgsqlDataAdapter(sql, conn);
                int iret = da.Fill(ds, tablename);
                if (iret >= 0)
                {
                    bret = true;
                }
            }
            catch (Exception e)
            {
                curerror = "filldataset error:" + e.Message + " sql=" + sql;
                //MyGlobal.debug = this.curerror;
            }
            finally
            {
                da.Dispose();
                conn.Dispose();
                da   = null;
                conn = null;
            }
            return(bret);
        }
예제 #24
0
        /// <summary>
        /// 指行指定的查询命令,并返回数据集。
        /// </summary>
        /// <param name="Command">要执行的查询。</param>
        /// <returns></returns>
        public override T ExecuteQuery <T>(CommandBuilder Command)
        {
            if (!typeof(T).Equals(typeof(DataTable)))
            {
                throw (new Exception("目标类型只能是 System.Data.DataTable."));
            }
            ClearError();
            NpgsqlDataAdapter DbAdapter = new NpgsqlDataAdapter(Command.Parsing(parserAdapter), (NpgsqlConnection)Connect());

            try
            {
                foreach (object p in Command.CommandParameters)
                {
                    DbAdapter.SelectCommand.Parameters.Add((NpgsqlParameter)p);
                }
                DbAdapter.SelectCommand.CommandType = Command.CommandType;
                DataTable dt = new DataTable();
                DbAdapter.Fill(dt);
                return((T)dt);
            }
            catch (Exception Ex)
            {
                _Error = new DbError(Ex.Message, DbAdapter.SelectCommand.CommandText, ConnectionString);
                return(null);
            }
            finally
            {
                DbAdapter.SelectCommand.Connection.Close();
                DbAdapter.SelectCommand.Connection.Dispose();
                DbAdapter.SelectCommand.Parameters.Clear();
                DbAdapter.Dispose();
            }
        }
예제 #25
0
        public IEnumerable <Goal> SelectGoals()
        {
            var connection = new NpgsqlConnection(connStr);

            connection.Open();

            var dataAdapter = new NpgsqlDataAdapter();
            var command     = new NpgsqlCommand("SELECT * FROM smartsaver.goal;", connection);

            //dataAdapter.SelectCommand = command;

            using NpgsqlDataReader rdr = command.ExecuteReader();

            while (rdr.Read())
            {
                yield return(new Goal
                {
                    Id = rdr.GetInt32(0),
                    Title = rdr.GetString(1),
                    Description = rdr.GetString(2),
                    Amount = rdr.GetDecimal(3),
                    Deadlinedate = rdr.GetDateTime(4),
                    Creationdate = rdr.GetDateTime(5)
                });
            }

            connection.Close();
            dataAdapter.Dispose();
        }
예제 #26
0
        public virtual DataSet ExecuteResultSet(NpgsqlCommand cmd)
        {
            DataSet           dts;
            NpgsqlDataAdapter adapter = null;

            try
            {
                if (cmd.Connection == null)
                {
                    cmd.Connection = this.Connection;
                }
                if (this._sqlTran != null)
                {
                    cmd.Transaction = this._sqlTran;
                }
                dts     = new DataSet();
                adapter = new NpgsqlDataAdapter(cmd);
                adapter.Fill(dts);
                return(dts);
            }
            catch (Exception ex)
            {
                this._InnerException = ex;
                throw ex;
            }
            finally
            {
                if (adapter != null)
                {
                    adapter.Dispose();
                }
            }
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _connection?.Dispose();
         _adapter?.Dispose();
     }
 }
예제 #28
0
        /// <summary>
        /// 填充DataTable
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        private DataTable FillData(NpgsqlCommand cmd)
        {
            var adt = new NpgsqlDataAdapter(cmd);
            var dt  = new DataTable();

            adt.Fill(dt);
            adt.Dispose();
            return(dt);
        }
예제 #29
0
        public DataTable Datasource(string sql)
        {
            DataSet           dataSet = new DataSet();
            NpgsqlDataAdapter da      = new NpgsqlDataAdapter(sql, conn);

            da.Fill(dataSet, "Custom_Command");
            da.Dispose();
            return(dataSet.Tables["Custom_Command"]);
        }
예제 #30
0
        static public Library.Funcionario FindById(long idFuncionario)
        {
            NpgsqlConnection  conexao = null;
            NpgsqlDataAdapter dap     = null;
            DataSet           ds      = null;

            Library.Funcionario Funcionario = null;
            try
            {
                conexao = new NpgsqlConnection(global::Connection.Connection.StringPostgree());

                dap = new NpgsqlDataAdapter("SELECT * FROM \"Funcionario\" WHERE id='" + idFuncionario + "'", conexao);

                ds = new DataSet();

                dap.Fill(ds, "Funcionario");

                if (ds.Tables["Funcionario"].Rows.Count == 1)
                {
                    DateTime date = DateTime.MinValue;
                    DateTime.TryParse(ds.Tables["Funcionario"].Rows[0]["nascimento"].ToString(), out date);

                    DateTime dataCadastro = DateTime.MinValue;
                    DateTime.TryParse(ds.Tables["Funcionario"].Rows[0]["dataCadastro"].ToString(), out dataCadastro);

                    Funcionario              = new Funcionario();
                    Funcionario.Id           = (long)ds.Tables["Funcionario"].Rows[0]["id"];
                    Funcionario.Login        = ds.Tables["Funcionario"].Rows[0]["login"].ToString();
                    Funcionario.Senha        = ds.Tables["Funcionario"].Rows[0]["senha"].ToString();
                    Funcionario.Bairro       = ds.Tables["Funcionario"].Rows[0]["bairro"].ToString();
                    Funcionario.Cep          = ds.Tables["Funcionario"].Rows[0]["cep"].ToString();
                    Funcionario.Celular      = ds.Tables["Funcionario"].Rows[0]["celular"].ToString();
                    Funcionario.Cpf          = ds.Tables["Funcionario"].Rows[0]["cpf"].ToString();
                    Funcionario.Email        = ds.Tables["Funcionario"].Rows[0]["email"].ToString();
                    Funcionario.Endereco     = ds.Tables["Funcionario"].Rows[0]["endereco"].ToString();
                    Funcionario.Estado       = ds.Tables["Funcionario"].Rows[0]["estado"].ToString();
                    Funcionario.Nascimento   = date;
                    Funcionario.Nome         = ds.Tables["Funcionario"].Rows[0]["nome"].ToString();
                    Funcionario.Rg           = ds.Tables["Funcionario"].Rows[0]["rg"].ToString();
                    Funcionario.Site         = ds.Tables["Funcionario"].Rows[0]["site"].ToString();
                    Funcionario.Telefone     = ds.Tables["Funcionario"].Rows[0]["telefone"].ToString();
                    Funcionario.DataCadastro = dataCadastro;
                }
                return(Funcionario);
            }
            catch (Exception ex)
            {
                Library.Classes.Logger.Error(ex);;
            }
            finally
            {
                conexao.Close();
                dap.Dispose();
                ds.Dispose();
            }
            return(null);
        }