p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   Show table in DataList (http://p2p.wrox.com/showthread.php?t=9798)

miguel.ossa February 26th, 2004 07:49 AM

Show table in DataList

I want to show a table in a datalist control. I've tried but I can't see nothing in the page when I executed. What's the problem?

            DataRow[] foundRows;

            ds = new DataSet("ALMACEN");
            dt = ds.Tables.Add("PRODUCTOS");
            dt.Columns.Add("id_producto", typeof (Int32));
            dt.Columns.Add("nombre", typeof (String));
            dt.PrimaryKey = new DataColumn[] { dt.Columns["id_productos"] };
            da = new SqlDataAdapter ("SELECT * FROM materia_prima", myConnection);
            da.Fill(ds, "PRODUCTOS");
            foundRows = dt.Select();
            for (int i = 0; i < foundRows.Length; i++)
                dr = dt.NewRow();

                dr[0] = foundRows[i]["id_producto"];
                dr[1] = foundRows[i]["nombre"];


            DataView dv = new DataView(dt);
            dlProductos.DataSource = dv;
            dlProductos.DataKeyField = "id_producto";

World only exists into your mind.

planoie February 26th, 2004 10:29 AM

It looks to me like you have greatly over complicated this code. I don't think you need to write all that code that creates a table for the dataset. When you use the data adapter to fill the dataset, it will create the table for you. That would at least simplify things. Start with that and see where you get.

ds = new DataSet("ALMACEN");
da = new SqlDataAdapter ("SELECT id_producto, nombre FROM materia_prima", myConnection);
da.Fill(ds, "PRODUCTOS");
dlProductos.DataSource = ds.Tables[0];
dlProductos.DataKeyField = "id_producto";

Work smarter, not harder.

All times are GMT -4. The time now is 07:05 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.