I'm starting in ASP.NET. I need to write data from two tables that are linked via ID. I would like to write in the cycle. Example: I have a table States and Cities table: 1.United states a. New York b. Washington c. Los Angeles d. Chicago e. Houston 2. Russia a. Moscow b. St. Petersburg c. Omsk d. Kazan 3. France a. Paris b. Lyon c. Marseille
In PHP I solve this problem as follows `
// cycle cities
$sql = mssql_query("SELECT * FROM States");
while($row = mssql_fetch_assoc($sql))
{
$id_state = row['ID_State'];
echo ($ row ['Name_State']);
// cycle city with id state
$sql_city = mssql_query("SELECT * FROM City WHERE ID_State = '. $id_state.'");
while ($row_city = mssql_fetch_assoc($sql_city))
{
echo($row['Name_city']);
}
}
Alternatively, just advice on how the operation is called, I do not know how to properly ask this in search
I tried Repeater in repeater but i have problem withI tried repeater in repeater, but I have a problem with passing parameters given line Repeater in Repeater
I tried also in DataReader DataReader, but this is an open DataReader reports an error. C# MySQL second DataReader in DataReader while loop
I also tried a treeview, but I am in the city must have a name and the name of the State, the same "name" and "name" which I can not have this. Treeview validation
I now tried good code
select.aspx.cs
SqlDataAdapter cmd1 = new SqlDataAdapter("SELECT * FROM V_Dic", cnn);
//Create and fill the DataSet.
DataSet ds = new DataSet();
cmd1.Fill(ds, "Dic");
//Create a second DataAdapter for the Titles table.
SqlDataAdapter cmd2 = new SqlDataAdapter("select * from T_Obdobi", cnn);
cmd2.Fill(ds, "Obdobi");
//Create a second DataAdapter for the Titles table.
SqlDataAdapter cmd3 = new SqlDataAdapter("select * from V_AktualizaceDic", cnn);
cmd3.Fill(ds, "OsCislo");
//Create the relation bewtween the Authors and Titles tables.
ds.Relations.Add("Obdobi",
ds.Tables["Dic"].Columns["ID_Dic"],
ds.Tables["Obdobi"].Columns["ID_Dic"]);
//ds.Relations.add
ds.Relations.Add("OsCislo",
ds.Tables["Dic"].Columns["ID_Dic"],
ds.Tables["OsCislo"].Columns["ID_Dic"]);
//Bind the Authors table to the parent Repeater control, and call DataBind.
parentRepeater.DataSource = ds.Tables["Dic"];
Page.DataBind();
select.aspx
<asp:Repeater ID="parentRepeater" runat="server">
<ItemTemplate>
<div class="accordion">
<div class="hlavni">
<%# DataBinder.Eval(Container.DataItem,"Dic") %>
</div>
<div class="rozbalovany">
<table>
<tr>
<td>Osobní číslo: </td>
<td><%# DataBinder.Eval(Container.DataItem,"OsCislo") %></td>
</tr>
<tr>
<td>Šetřené zdaňovací období: </td>
<td>
<div class="box2">
<!-- start child repeater -->
<asp:Repeater ID="childRepeater" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).Row.GetChildRows("Obdobi") %>'
runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "[\"Obdobi\"]")%><br />
</ItemTemplate>
</asp:Repeater>
</div>
</td>
</tr>
</table>
<h3>Aktualizace:</h3>
<!-- end child repeater -->
<div class="box">
<table class="aktualizace" style="border: 1px solid #e9e9e9">
<tr>
<td><strong>Osobní číslo</strong></td>
<td>Jméno a Příjmení</td>
<td>Datum Aktualizace</td>
<td>Poznámka</td>
<td>Šetřené zdaňovací období</td>
<td>Změna Řešitele</td>
<td>Změna Plné moci</td>
<td>Záznam v Insolvenčním řejstříku</td>
<td>Významná změna s vazbou na data v OR</td>
<td>Jiná významná změna</td>
</tr>
<asp:Repeater ID="childRepeater2" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).Row.GetChildRows("OsCislo") %>'
runat="server">
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "[\"OsCislo\"]")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
but, I can't add parameter to first select. I tried
cmd1.SelectCommand.Parameters.Add("@EvCislo", SqlDbType.NVarChar, 50, "EvCislo");
but program have error message "this constraint cannot be enabled as not all values have corresponding parent values." this example i see here