Example #1
0
    // get the existing users from users table.
    // show the users details below save/update button.
    private void BindGridView()
    {
        try
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            // sql query to get the list of users
            SqlCommand     cmd = new SqlCommand("select id as \"Book Id\", name as Name, notes as Description,Author,publication,price,quantity from books order by id;", conn);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet        ds  = new DataSet();

            // Fill the Grid view
            adp.Fill(ds);
            GridViewBooks.DataSource = ds;
            GridViewBooks.DataBind();
            lbltotalcount.Text = GridViewBooks.Rows.Count.ToString();
        }
        catch (SqlException ex)
        {
            throw ex;
        }
        finally
        {
            conn.Close();
        }
    }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Selects all item details from collection tables
            SqlConnection connection = new SqlConnection("Server = Localhost\\SQLEXPRESS;Database = Comp229TeamProject;Integrated Security=True");
            SqlCommand    comm       = new SqlCommand("SELECT * from Collections", connection);

            try
            {
                //Binds the data and displays
                connection.Open();
                SqlDataReader reader = comm.ExecuteReader();

                GridViewBooks.DataSource = reader;
                GridViewBooks.DataBind();

                connection.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }