I'm trying to join 2 DataTables
but I' m getting this error:
Object reference not set to an instance of an object
this is what I'm doing:
DataTable NodeDataTable = new DataTable();
DataTable sdosDataTable = new DataTable();
private DataTable NodedataTable()
{
XmlTextReader xmlreader = new XmlTextReader(Server.MapPath("stuff.xml"));
DataSet ds = new DataSet();
ds.ReadXml(xmlreader);
xmlreader.Close();
if (ds.Tables.Count != 0)
{
NodeDataTable = ds.Tables[22];
}
return NodeDataTable;
}
private DataTable SdosDataTable()
{
XmlTextReader xmlreader = new XmlTextReader(Server.MapPath("stuff.xml"));
DataSet ds = new DataSet();
ds.ReadXml(xmlreader);
xmlreader.Close();
if (ds.Tables.Count != 0)
{
sdosDataTable = ds.Tables[10];
}
return sdosDataTable;
}
and to join both DataTables:
private void JoinNodeSdosDT()
{
DataColumn obj_NodeID, obj_SdosID;
DataSet ds1 = new DataSet();
NodeDataTable = NodeDataTable.Copy();
sdosDataTable = sdosDataTable.Copy();
ds1.Tables.Add(NodeDataTable);
ds1.Tables.Add(sdosDataTable);
obj_NodeID = ds1.Tables["node"].Columns["node_Id"];
obj_SdosID = ds1.Tables["sdos"].Columns["node_Id"];
sdosDataTable.Columns.Add("typeCodee");
DataRelation obj_NodeandSdosRelation = new DataRelation("dept_reln", obj_NodeID, obj_SdosID);
ds1.Relations.Add(obj_NodeandSdosRelation);
foreach (DataRow dr_NodeSods in ds1.Tables["sdos"].Rows)
{
DataRow dr_NondeeeR = dr_NodeSods.GetParentRow("dept_reln");
dr_NodeSods["typeCodee"] = dr_NondeeeR["typeCode"];
}
DataTable dtResult = ds1.Tables["sdos"].DefaultView.ToTable(false, "node_Id", "typeCode", "sdos_Id");
GridView1.DataSource = dtResult;
}
there is some any matching ID what can I do here to resolve my problem.
I removed The datatable Images there is no use of them.