在ASP.NET 2.0中使用OdbcDataReader从MySQL数据库嵌套中继器

在ASP.NET 2.0中使用OdbcDataReader从MySQL数据库嵌套中继器,mysql,data-binding,dataset,relational-database,nested-sets,Mysql,Data Binding,Dataset,Relational Database,Nested Sets,我刚才问了这个问题,但没有回答,从那以后我一直忙于其他事情,但今天又回来了,仍然无法破解它 我原来的问题是: 现在,从那以后,我一直在努力了解我在阅读这篇文章时做错了什么 以及各种Microsfot教程 我想我在填充数据集时遗漏了一个步骤或误解了一些东西。。。今天上午,我一直在兜圈子,现在我感到非常困惑 这让我很恼火 我已经做到了这一点:顺便说一下,我正在使用ASP.NET2.0和MySQL数据库 Sub getCategories() Handles Me.Load Dim DBCo

我刚才问了这个问题,但没有回答,从那以后我一直忙于其他事情,但今天又回来了,仍然无法破解它

我原来的问题是:

现在,从那以后,我一直在努力了解我在阅读这篇文章时做错了什么 以及各种Microsfot教程

我想我在填充数据集时遗漏了一个步骤或误解了一些东西。。。今天上午,我一直在兜圈子,现在我感到非常困惑

这让我很恼火

我已经做到了这一点:顺便说一下,我正在使用ASP.NET2.0和MySQL数据库

Sub getCategories() Handles Me.Load

    Dim DBConnection = ConfigurationManager.ConnectionStrings("dbConnNew").ConnectionString
    Dim connection As OdbcConnection = New OdbcConnection(DBConnection)
    Dim connect As New OdbcCommand("SELECT masterCat.name AS masterCat, masterCat.id as mcId, category.id as cId, category.name AS category, category.mapsTo as catMapsTo, subCat.mapsTo as subCatMapsTo, subCat.name AS subCat FROM masterCat INNER JOIN category ON masterCat.id = category.mapsTo INNER JOIN subCat ON category.id = subCat.mapsTo WHERE masterCat.id <> '9' ORDER BY masterCat.priority", connection)

    Dim DS As New DataSet()
    connection.Open()
    Dim read As OdbcDataReader = connect.ExecuteReader(CommandBehavior.CloseConnection)
    DS.Load(read, LoadOption.OverwriteChanges, "masterCat, category, subCat")

    'DS.Relations.Add("mCatid", DS.Tables("masterCat").Columns("mcId"), DS.Tables("category").Columns("cId")) << This Line Breaks

    connection.Close()

    masterCat.DataSource = DS
    masterCat.DataBind()

End Sub

Private Sub CategoryRepeater_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles masterCat.ItemDataBound
    Dim item As RepeaterItem = e.Item
    If (item.ItemType = ListItemType.Item) OrElse (item.ItemType = ListItemType.AlternatingItem) Then
        Dim catRpt = DirectCast(item.FindControl("catRepeater"), Repeater)
        Dim drv As DataRowView = DirectCast(item.DataItem, DataRowView)
        catRpt.DataSource = drv.CreateChildView("mcId")
        catRpt.DataBind()
    End If
End Sub
类别

副歌

上面的SQL查询正确返回包含以下列的整个数据:

masterCat   - name of the master category
mcId        - ID of the master category
cId         - ID of a category
category    - name of a category
catMapsTo   - the ID of the masterCategory to which category relates
subCat       - subCategory name
subCatMapsTo - the ID of the category to which the subCategory relates
在这个例子中,我需要的是两个层次的东西

猫主人 类别 类别 类别 猫主人 类别 类别 类别 猫主人 类别 类别 类别

非常感谢您的帮助

id    |    name    | priority (for sorting)
id    |    name    |    mapsTo (this is the ID of the masterCat to which this relates)
 id    |    name    | mapsTo (ID of the category to which this relates)
masterCat   - name of the master category
mcId        - ID of the master category
cId         - ID of a category
category    - name of a category
catMapsTo   - the ID of the masterCategory to which category relates
subCat       - subCategory name
subCatMapsTo - the ID of the category to which the subCategory relates
    </li>