|
 |
aspx thread: DataGrid binding
Message #1 by Lars Solem <Lars.Solem@v...> on Tue, 12 Dec 2000 09:39:14 +0100
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C06417.A57A9140
Content-Type: text/plain;
charset="iso-8859-1"
Hi again,
I try to bind data to a datagrid, but nothing shows up. I use the example
from the DataSet Class description in the .NET Framework Reference. When I
debug, I can see that my data is in a dataset inside my datagrid
(myDataGrid.DataSource.DataSetView.DataSet), but nothing shows up in the
DataGrid in the WebForm.
Please help,
Lars
Message #2 by "Christine Anwar" <christine.anwar@i...> on Tue, 12 Dec 2000 00:54:45 -0800
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_000C_01C063D6.1F8DC5F0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
can u please forward the code ???
Christine
-----Original Message-----
From: Lars Solem [mailto:Lars.Solem@v...]
Sent: Tuesday, December 12, 2000 12:39 AM
To: ASP+
Subject: [aspx] DataGrid binding
Hi again,
I try to bind data to a datagrid, but nothing shows up. I use the example
from the DataSet Class description in the .NET Framework Reference. When I
debug, I can see that my data is in a dataset inside my datagrid
(myDataGrid.DataSource.DataSetView.DataSet), but nothing shows up in the
DataGrid in the WebForm.
Please help,
Lars
Message #3 by Lars Solem <Lars.Solem@v...> on Tue, 12 Dec 2000 10:08:40 +0100
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C0641B.C13E2C50
Content-Type: text/plain;
charset="iso-8859-1"
Ok, here it is in its current form. I use the SQLConnection and -Command
instead of ADO.. I also removed the DataGrid1.DataMember = "Suppliers",
because I couldn't find the DataMember (maybe not implemented yet). I added
the DataGrid1.DataBind() to the end of the code.
//1 Create the connection. Modify the connection string below.
SQLConnection cConn = new SQLConnection("myServ","sa","","Northwind");
//2 Create a DataSet
DataSet cDS = new DataSet();
//3 Create an SQL Command. Set ActiveConnection and CommandText
SQLCommand cCommand = new SQLCommand();
cCommand.ActiveConnection = cConn;
cCommand.CommandText = "select * from Suppliers";
//4 Create and configure SQLDataSetCommand
SQLDataSetCommand cDSCommand = new SQLDataSetCommand();
cDSCommand.SelectCommand = cCommand;
//5 Add TableMappings to ADODataSetCommand.
cDSCommand.TableMappings.Add("Table", "Suppliers");
//6 Invoke FillDataSet
cDSCommand.FillDataSet(cDS);
//7 Get second table. Create a second Command.
SQLCommand cCommand2 = new SQLCommand ();
SQLDataSetCommand cDSCommand2 = new SQLDataSetCommand();
//Use the same connection for the Command.
cCommand2.ActiveConnection = cConn;
// Select all columns and rows from the Products table.
cCommand2.CommandText = "SELECT * FROM Products";
// Set the SelectCommand property to the Command.
cDSCommand2.SelectCommand = cCommand2;
// Add a TableMapping. This tells the DataSet how to map columns
// from the table to the DataTable.
cDSCommand2.TableMappings.Add ("Table", "Products");
cDSCommand2.FillDataSet(cDS);
//8 Create a DataRelation to link the two tables.
DataRelation dr;
DataColumn dc1;
DataColumn dc2;
// Get the parent and child columns of the two tables.
dc1 = cDS.Tables["Suppliers"].Columns["SupplierID"];
dc2 = cDS.Tables["Products"].Columns["SupplierID"];
dr = new DataRelation("suppliers2products", dc1, dc2);
cDS.Relations.Add(dr);
// Bind the DataSet to a DataGrid to see the tables.
// Create a DataSetView using the DataSet.
DataSetView dsv=new DataSetView(cDS);
// Set the DataSource of a DataGrid control to the DataSetView
DataGrid1.DataSource = dsv;
DataGrid1.DataBind();
Lars
-----Original Message-----
From: Christine Anwar [mailto:christine.anwar@i...]
Sent: 12. desember 2000 09:55
To: ASP+
Subject: [aspx] RE: DataGrid binding
can u please forward the code ???
Christine
-----Original Message-----
From: Lars Solem [mailto:Lars.Solem@v...]
Sent: Tuesday, December 12, 2000 12:39 AM
To: ASP+
Subject: [aspx] DataGrid binding
Hi again,
I try to bind data to a datagrid, but nothing shows up. I use the example
from the DataSet Class description in the .NET Framework Reference. When I
debug, I can see that my data is in a dataset inside my datagrid
(myDataGrid.DataSource.DataSetView.DataSet), but nothing shows up in the
DataGrid in the WebForm.
Please help,
Lars
Message #4 by Susan Warren <swarren@m...> on Tue, 12 Dec 2000 03:08:44 -0800
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C0642B.E49E4618
Content-Type: text/plain;
charset="iso-8859-1"
Lars --
The problem is that you can't bind an ASP.NET control to a DataSetView,
however you can bind it to a DataView. (DataSetView is used by Windows
Forms only.) A DataView is a cursor to a single DataTable (in a DataSet or
not). For example:
DataGrid1.DataSource = cDS.Tables["Suppliers"].DefaultView;
For relational data like Northwind, you can always do the join in the
database query or a sproc. This will yield a single table in your result
set that includes data from multiple tables. For an example of this using
DataSet/DataView, trace the OrderList page through the GetCustomerOrders()
method in OrdersDB.cs to the OrderList stored procedure in IBuySpy. (
http://www.ibuyspy.com <http://www.ibuyspy.com> ).
And you are correct, DataMember is not yet implemented (but will be in
Beta2).
hth,
Susan
-----Original Message-----
From: Lars Solem [mailto:Lars.Solem@v...]
Sent: Tuesday, December 12, 2000 1:09 AM
To: ASP+
Subject: [aspx] RE: DataGrid binding
Ok, here it is in its current form. I use the SQLConnection and -Command
instead of ADO.. I also removed the DataGrid1.DataMember = "Suppliers",
because I couldn't find the DataMember (maybe not implemented yet). I added
the DataGrid1.DataBind() to the end of the code.
//1 Create the connection. Modify the connection string below.
SQLConnection cConn = new SQLConnection("myServ","sa","","Northwind");
//2 Create a DataSet
DataSet cDS = new DataSet();
//3 Create an SQL Command. Set ActiveConnection and CommandText
SQLCommand cCommand = new SQLCommand();
cCommand.ActiveConnection = cConn;
cCommand.CommandText = "select * from Suppliers";
//4 Create and configure SQLDataSetCommand
SQLDataSetCommand cDSCommand = new SQLDataSetCommand();
cDSCommand.SelectCommand = cCommand;
//5 Add TableMappings to ADODataSetCommand.
cDSCommand.TableMappings.Add("Table", "Suppliers");
//6 Invoke FillDataSet
cDSCommand.FillDataSet(cDS);
//7 Get second table. Create a second Command.
SQLCommand cCommand2 = new SQLCommand ();
SQLDataSetCommand cDSCommand2 = new SQLDataSetCommand();
//Use the same connection for the Command.
cCommand2.ActiveConnection = cConn;
// Select all columns and rows from the Products table.
cCommand2.CommandText = "SELECT * FROM Products";
// Set the SelectCommand property to the Command.
cDSCommand2.SelectCommand = cCommand2;
// Add a TableMapping. This tells the DataSet how to map columns
// from the table to the DataTable.
cDSCommand2.TableMappings.Add ("Table", "Products");
cDSCommand2.FillDataSet(cDS);
//8 Create a DataRelation to link the two tables.
DataRelation dr;
DataColumn dc1;
DataColumn dc2;
// Get the parent and child columns of the two tables.
dc1 = cDS.Tables["Suppliers"].Columns["SupplierID"];
dc2 = cDS.Tables["Products"].Columns["SupplierID"];
dr = new DataRelation("suppliers2products", dc1, dc2);
cDS.Relations.Add(dr);
// Bind the DataSet to a DataGrid to see the tables.
// Create a DataSetView using the DataSet.
DataSetView dsv=new DataSetView(cDS);
// Set the DataSource of a DataGrid control to the DataSetView
DataGrid1.DataSource = dsv;
DataGrid1.DataBind();
Lars
-----Original Message-----
From: Christine Anwar [mailto:christine.anwar@i...]
Sent: 12. desember 2000 09:55
To: ASP+
Subject: [aspx] RE: DataGrid binding
can u please forward the code ???
Christine
-----Original Message-----
From: Lars Solem [mailto:Lars.Solem@v...]
Sent: Tuesday, December 12, 2000 12:39 AM
To: ASP+
Subject: [aspx] DataGrid binding
Hi again,
I try to bind data to a datagrid, but nothing shows up. I use the example
from the DataSet Class description in the .NET Framework Reference. When I
debug, I can see that my data is in a dataset inside my datagrid
(myDataGrid.DataSource.DataSetView.DataSet), but nothing shows up in the
DataGrid in the WebForm.
Please help,
Lars
|
|
 |