Hello,
I am having a dataset in which am having 2 tables,i want to build relation between them. my 2 tables are as listed below.
CREATE TABLE SERVICES
(VOY_SERVICES_SERVICE_ID INT PRIMARY KEY IDENTITY(1,1),
VOY_SERVICES_SERVICE_NAME VARCHAR(50))
CREATE TABLE SUB_SERVICES
(VOY_SUB_SERVICES_SERVICE_ID INT PRIMARY KEY IDENTITY(1,1),
VOY_SERVICES_SERVICE_ID INT FOREIGN KEY REFERENCES SERVICES (VOY_SERVICES_SERVICE_ID),
VOY_SUB_SERVICES_SERVICE_NAME VARCHAR(50))
i tried this code,
SqlConnection con = new SqlConnection( "Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=VOY;Integrated Security=True");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from SERVICES;select * from SUB_SERVICES as sub,SERVICES as services where sub.VOY_SERVICES_SERVICE_ID = services.VOY_SERVICES_SERVICE_ID", con);
da.TableMappings.Add("Table";, "SERVICES");
da.TableMappings.Add("Table1";, "SUB_SERVICES");
DataSet ds2 = new DataSet();
da.Fill(ds2);
ds2.Relations.Add(ds2.Tables["SERVICES"].Columns["VOY_SERVICES_SERVICE_ID"],
ds2.Tables["SUB_SERVICES"].Columns["VOY_SERVICES_SERVICE_ID"]);
ds2.Relations[0].Nested = true;
ds2.Relations.Add("subservices", ds2.Tables[" SUB_SERVICES"].Columns["VOY_SUB_SERVICES_SERVICE_ID"], ds2.Tables["SUB_SERVICES_CATEGORIES "].Columns["VOY_SUB_SERVICES_SERVICE_ID"]);
ds2.Relations[1].Nested = true;
services_repeater.DataSource = ds2;
services_repeater.DataBind();
con.Close();
am getting the error as "Object reference not set to an instance of an object" at
ds2.Tables["SUB_SERVICES"].Columns["VOY_SERVICES_SERVICE_ID"]) please help me. am using the repeaters so that i can get the chechboxes in nested format, and my .aspx page is as shown,
<asp:Repeater id="services_repeater" runat="server" EnableViewState="false">
<ItemTemplate>
Services:<%#DataBinder.Eval(Container.DataItem,"VOY_SERVICES_SERVICE_ID") %>
<%#DataBinder.Eval(Container.DataItem,"VOY_SERVICES_SERVICE_NAME") %>
<br />
<asp:Repeater runat="server" EnableViewState="false" DataSource='<%# GetChildRelation(Container.DataItem,"SERVICES") %>'>
<ItemTemplate>
SubserviceID:<b><%#DataBinder.Eval(Container.DataItem,"VOY_SUB_SERVICES_SERVICE_ID")%> </b>
<br />
<asp:Repeater runat="server" EnableViewState="false" DataSource='<%#GetChildRelation (Container.DataItem,"SUB_SERVICES")%>'>
<ItemTemplate>
<b><%#DataBinder.Eval(Container.DataItem,"VOY_SUB_SERVICES_CATEGORIES_NAME") %></b>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
any solution is welcome.