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.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace relation_test
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnectio* n thisConnection;
protected System.Web.UI.WebControls.DataGrid* DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string found = "ae627ecb-a964-4672-a1f7-33261f450a6c";*
DataSet shoppingCartDataSet = new DataSet();
SqlDataAdapter shoppingCartAdapter = 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);
shoppingCartAdapter.Fill(shoppingC* artDataSet, "ShoppingCart");
photoAdapter.Fill(shoppingCartData* Set, "T_Photo");
DataRelation thisRelation = shoppingCartDataSet.Relations.Add(*
"PhotoOrder",
shoppingCartDataSet.Tables[ShoppingCart].Columns[PhotoID],
shoppingCartDataSet.Tables[T_Photo].Columns[PhotoID]);
DataGrid1.DataSource = shoppingCartDataSet;
DataGrid1.DataBind();
}
}
}
}
I found that, the datagrid can locate the columns in frist table
"ShoppingCart" 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. 2 2046
hi,
you cannot do it, it has to be one table.
What you can do though, is create "link" columns, where a column in one
table (parent) is a reference to a column in a child table. Take a look at
DataColumn.Expression in MSDN
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Wing" <li******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace relation_test
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnectio* n thisConnection;
protected System.Web.UI.WebControls.DataGrid* DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string found = "ae627ecb-a964-4672-a1f7-33261f450a6c";*
DataSet shoppingCartDataSet = new DataSet();
SqlDataAdapter shoppingCartAdapter = 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);
shoppingCartAdapter.Fill(shoppingC* artDataSet, "ShoppingCart");
photoAdapter.Fill(shoppingCartData* Set, "T_Photo");
DataRelation thisRelation = shoppingCartDataSet.Relations.Add(*
"PhotoOrder",
shoppingCartDataSet.Tables[ShoppingCart].Columns[PhotoID],
shoppingCartDataSet.Tables[T_Photo].Columns[PhotoID]);
DataGrid1.DataSource = shoppingCartDataSet;
DataGrid1.DataBind();
}
}
}
}
I found that, the datagrid can locate the columns in frist table
"ShoppingCart" 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.
thanks for your advice, I will take a look at DataColumn, hope that can
help
thanks a lot This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Billy Jacobs |
last post by:
I am using a datagrid to display some data. I need to
create 2 header rows for this grid with columns of
varying spans. In html it would be the following.
<Table>
<tr>
<td colspan=8>Official...
|
by: DraguVaso |
last post by:
Hi,
I need a function that gives me the number of Columns shown in a DataGrid.
So I don't need to know the number of columns shown in tha DataSource,
because this number can be completely...
|
by: Fresh Air Rider |
last post by:
Hello
Does anyone know how to display data from a data source such as an
array or SqlDataReader or XML etc within an HTML table whose number of
columns can change according to the value of a...
|
by: Diego TERCERO |
last post by:
Hi...
I'm working on a tool for editing text resources for a family of software
product my company produces.
These text resources are found in a SQL Server database, in a table called...
|
by: Alexander |
last post by:
Hi, I am using a DataGrid and assign a DataTable as a DataSource to
it:
void ShowData()
{
DataTable myNewDataTable = new DataTable();
... // fill table
this.m_DataGrid1.DataSource =...
|
by: CSL |
last post by:
I am using the DataGrid in a Windows Application, how can
I adjust the widths of each column individually.
|
by: jwogick |
last post by:
I'm hoping someone can help me!
I just have a simple form with a datagrid displaying child records
from a dataset that contains two related tables Parent
table>Clients Child table>cases. using the...
|
by: Jeff |
last post by:
I am stuck on trying to generate two columns headers for a datagrid on
form load. I can use a datatable as the datasource and get the results
I want, but I want to set different column widths and...
|
by: RN1 |
last post by:
I am retrieving records from a DB table & displaying them in a
DataGrid. There are 6 columns in the DB table & the DataGrid displays
all the 6 columns. This is the code:
<script runat="server">...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |