Hi all,
I am using Microsoft Visual Studio .NET 2003 to program my code. I have
following question.
I am trying to adding a few bound columns which from a dataset that
containing 2 tables to a datagrid, and display to the user. once I run
it, I have error msg:
"A field or property with the name 'PhotoName' was not found on the
selected datasource."
where PhotoName is the first Column in second table of the dataset.
my code is showing below
---------------------------------- ---------
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;
namespace relation_test
{
public class WebForm1 : System.Web.UI.P age
{
protected System.Data.Sql Client.SqlConne ctio n thisConnection;
protected System.Web.UI.W ebControls.Data Grid DataGrid1;
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
string found = "ae627ecb-a964-4672-a1f7-33261f450a6c";
DataSet shoppingCartDat aSet = new DataSet();
SqlDataAdapter shoppingCartAda pter = new SqlDataAdapter (
"SELECT * FROM ShoppingCart WHERE CartID='"+found +"'", thisConnection) ;
SqlDataAdapter photoAdapter = new SqlDataAdapter ("SELECT PhotoID,
PhotoName, Price FROM T_Photo WHERE PhotoID IN (SELECT PhotoID FROM
ShoppingCart WHERE CartID='"+found +"')", thisConnection) ;
shoppingCartAda pter.Fill(shopp ingC artDataSet, "ShoppingCart") ;
photoAdapter.Fi ll(shoppingCart Data Set, "T_Photo");
DataRelation thisRelation = shoppingCartDat aSet.Relations. Add(
"PhotoOrder ",
shoppingCartDat aSet.Tables[ShoppingCart].Columns[PhotoID],
shoppingCartDat aSet.Tables[T_Photo].Columns[PhotoID]);
DataGrid1.DataS ource = shoppingCartDat aSet;
DataGrid1.DataB ind();
}
}
}
}
I found that, the datagrid can locate the columns in frist table
"ShoppingCa rt" with no problem, but can not find the columns in second
table "T_Photo".
Can anyone tell me how to solve this problem, so I can display any
columns selectively from the dataset.
thanks for your time.
I am using Microsoft Visual Studio .NET 2003 to program my code. I have
following question.
I am trying to adding a few bound columns which from a dataset that
containing 2 tables to a datagrid, and display to the user. once I run
it, I have error msg:
"A field or property with the name 'PhotoName' was not found on the
selected datasource."
where PhotoName is the first Column in second table of the dataset.
my code is showing below
---------------------------------- ---------
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;
namespace relation_test
{
public class WebForm1 : System.Web.UI.P age
{
protected System.Data.Sql Client.SqlConne ctio n thisConnection;
protected System.Web.UI.W ebControls.Data Grid DataGrid1;
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
string found = "ae627ecb-a964-4672-a1f7-33261f450a6c";
DataSet shoppingCartDat aSet = new DataSet();
SqlDataAdapter shoppingCartAda pter = new SqlDataAdapter (
"SELECT * FROM ShoppingCart WHERE CartID='"+found +"'", thisConnection) ;
SqlDataAdapter photoAdapter = new SqlDataAdapter ("SELECT PhotoID,
PhotoName, Price FROM T_Photo WHERE PhotoID IN (SELECT PhotoID FROM
ShoppingCart WHERE CartID='"+found +"')", thisConnection) ;
shoppingCartAda pter.Fill(shopp ingC artDataSet, "ShoppingCart") ;
photoAdapter.Fi ll(shoppingCart Data Set, "T_Photo");
DataRelation thisRelation = shoppingCartDat aSet.Relations. Add(
"PhotoOrder ",
shoppingCartDat aSet.Tables[ShoppingCart].Columns[PhotoID],
shoppingCartDat aSet.Tables[T_Photo].Columns[PhotoID]);
DataGrid1.DataS ource = shoppingCartDat aSet;
DataGrid1.DataB ind();
}
}
}
}
I found that, the datagrid can locate the columns in frist table
"ShoppingCa rt" with no problem, but can not find the columns in second
table "T_Photo".
Can anyone tell me how to solve this problem, so I can display any
columns selectively from the dataset.
thanks for your time.
Comment