Hi mates
I am getting the following error "Invalid object name 't1'.Invalid object name 'relT1T2'."
from this line of code " String SQLREL = "SELECT t1.SubCategory2Name, t1.CityName, SubCategory2Name,relT1T2.N FROM " +
"t1 INNER JOIN relT1T2 ON t1.PKSUBCAT2ID = relT1T2.FKSUBCAT2ID";"
i am basically using datarelation and the relation is working fine and is showing all the data for the parent and child tables but while constructing sql i get above mentioned error.can some one pls help me out.
the full code is given below:
DataColumn parentCol;DataColumn childCol;
parentCol = ds11.Tables["t1"].Columns["PKSUBCAT2ID"];
childCol = ds11.Tables["t2"].Columns["FKSUBCAT2ID"];
DataRelation relT1T2;
relT1T2 = new DataRelation("T1T2", parentCol, childCol);
ds11.Relations.Add(relT1T2);
Response.Write(ds11.Tables["t1"].Rows.Count);
foreach (DataRow rowParent in ds11.Tables["t1"].Rows)
{
foreach (DataRow rowChild in rowParent.GetChildRows(relT1T2))
{
Response.Write(ds11.Tables["t1"].Rows.Count);//test code
DataView dv1 = ds11.Tables["t1"].DefaultView;
String SQLREL = "SELECT t1.SubCategory2Name, t1.CityName, SubCategory2Name,relT1T2.N FROM " +
"t1 INNER JOIN relT1T2 ON t1.PKSUBCAT2ID = relT1T2.FKSUBCAT2ID";
DataSet ds77 = new DataSet();
SqlConnection cn77 = new SqlConnection(CONN1);
cn77.Open();
SqlDataAdapter da77 = new SqlDataAdapter(SQLREL, cn77);
da77.Fill(ds77);
DataList1.DataSource = ds77.Tables[0].DefaultView;
DataList1.DataBind();
cn77.Close();
Hi gurjeetsaini,
Could you please post your connection string "CONN1" here please?
Also, it seems to me you are drive data from your datarelation class, Based on my understanding, datarelation class is not designed for that purpose (it only represent relationships between tables in a dataset, it cannot be used like tables or datasets).
Hope my suggestion helps
No comments:
Post a Comment