Пример #1
0
 protected void select_All()
 {
     try
     {
         //Opening the connection to the DB
         NpgsqlConnection conn = new NpgsqlConnection(connstring);
         conn.Open();
         //The Select SQL Command to execute
         string            sql = "SELECT * FROM projet";
         NpgsqlDataAdapter da  = new NpgsqlDataAdapter(sql, conn);
         da.Fill(ds);
         conn.Close();
         if (ds.Tables[0].Rows.Count > 0)
         {
             ProjectGridView.DataSource = ds;
             ProjectGridView.DataBind();
         }
         else
         {
             ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
             ProjectGridView.DataSource = ds;
             ProjectGridView.DataBind();
             int columncount = ProjectGridView.Rows[0].Cells.Count;
             ProjectGridView.Rows[0].Cells.Clear();
             ProjectGridView.Rows[0].Cells.Add(new TableCell());
             ProjectGridView.Rows[0].Cells[0].ColumnSpan = columncount;
             ProjectGridView.Rows[0].Cells[0].Text       = Resources.General.NoRecordFound;
         }
     }
     catch (Exception msg)
     {
         //DB error are trown in a Label
         ErrorManagement.Text = Resources.General.AnErrorHasOccured + ": " + msg.ToString();
     }
 }
 public void Display()
 {
     using (SqlConnection connection = new SqlConnection(con))
     {
         SqlCommand cmd2 = new SqlCommand("DisplayProject", connection);
         cmd2.CommandType = CommandType.StoredProcedure;
         cmd2.Parameters.AddWithValue("@CId", DBNull.Value);
         connection.Open();
         ProjectGridView.DataSource = cmd2.ExecuteReader();
         ProjectGridView.DataBind();
     }
 }