开发者

How to populate a gridview with database data help?

Ok first off do I need to add a data source in the designer? or will the DataSource = reader take care of that, second how can I limit it to the users badge number entered n the source page ie: user enters 3 digit code gets his hours worked typical time sheet format.

Can you guys please help me I'm new to asp c# and databases but I'm trying to learn more each day? oh and can you explain in laymans terms

  string cmdquery = "SELECT * FROM EMPLOYEES WHERE BADGE ='" + Badge + "'";
                string 开发者_StackOverflowclquery = " SELECT * FROM CLOCK_HISTORY WHERE BADGE ='" + Badge + "'";


            OracleCommand cmd = new OracleCommand(cmdquery);
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            conn.Open();
            using (OracleDataReader reader = cmd.ExecuteReader())
            {

                while (reader.Read())
                {
                    this.xUserNameLabel.Text += reader["EMPLOYEE_NAME"];
                    this.xDepartmentLabel.Text += reader["REPORT_DEPARTMENT"];

                }




            }

            conn.Close();


            OracleCommand clq = new OracleCommand(clquery);
            clq.Connection = conn;
            clq.CommandType = CommandType.Text;
            conn.Open();

            using (OracleDataReader reader = clq.ExecuteReader())
            {

                    xHoursGridView.DataSource = reader;
                    xHoursGridView.DataBind();
            }


You don't need a DataSource control in the markup if you're setting the DataSource property of your Gridview e.g. DataSource = reader - these are (essentially) two different ways to achieve the same result. Using a DataSource control allows you to connect the controls on your page to a database (databinding), without writing any code - there's a useful article on using them here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜