Nested datarelations (parent child relations) eller list underkategori efter hovedkategori.
Jeg har et lille problem med at få vist et dataset i et datagrid eller lign. Her er min kode. det virker fint med at udskrive data i en alm. tabel, men at få det over i en asp sever control, volder mig problemmer.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim nwindConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\oledb_connection\cellcode.mdb")
Dim MainCategoryDA As OleDbDataAdapter = New OleDbDataAdapter("SELECT ID,Category FROM tblCategory", nwindConn)
Dim SubcategoryDA As OleDbDataAdapter = New OleDbDataAdapter("SELECT ID,Subject,Description, CategoryID FROM tblSourceCode", nwindConn)
nwindConn.Open()
Dim categoriesDS As DataSet = New DataSet("Category_Relations")
MainCategoryDA.Fill(categoriesDS, "MainCategory")
SubcategoryDA.Fill(categoriesDS, "SubCategory")
nwindConn.Close()
Dim MainSubCategoryRelation As DataRelation = categoriesDS.Relations.Add("CatRel", categoriesDS.Tables("MainCategory").Columns("ID"), categoriesDS.Tables("SubCategory").Columns("CategoryID"))
og så har du... eksempel fra ms hjælp <script language="C#" runat="server"> void Page_Load(Object sender, EventArgs e) { // Create a connection to the "pubs" database located // on the local computer. SqlConnection myConnection = new SqlConnection("server=nfo1;" + "database=pubs;uid=sa;pwd=a"); // Connect to the SQL database using a SQL SELECT query to get // all the data from the "Titles" table. SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM" + " Titles", myConnection); // Create and fill a DataSet. DataSet ds = new DataSet(); myCommand.Fill(ds); // Bind MyRepeater to the DataSet. MyRepeater is the ID of the // Repeater control in the HTML section of the page. MyRepeater.DataSource = ds; MyRepeater.DataBind(); } </script>
<ASP:Repeater id="MyRepeater" runat="server"> <HeaderTemplate> <Table width="100%" style="font: 8pt verdana"> <tr style="background-color:DFA894"> <th> Title </th> <th> Title ID </th> <th> Type </th> <th> Publisher ID </th> <th> Price </th> </tr> </HeaderTemplate>
det jeg gerne vil have er at jeg kan udskrive data fra de 2 SELECTS i et DATAGRID, DATALIST eller DATAREPETER. Så jeg slipper for de to For Each Next loops på kode siden. (der bare kobler data til et <div> tag).
her er min funktion (laver en select med under punkter
Public Function MakeCatSelect (ByVal pSelected As Integer, ByVal sSelected As Integer) Try
Dim strSQL = "SELECT ID, sk_ID, iType, sHeading FROM tbl_pages WHERE bActive = 1 AND sk_ID = 0 ORDER BY sk_ID, iIndex "
Dim strSQL2 = "SELECT ID, sk_ID, iType, sHeading FROM tbl_pages WHERE bActive = 1 AND sk_ID > 0 " & _ " AND sk_ID IN (SELECT ID FROM tbl_pages WHERE bActive = 1 AND sk_ID = 0) ORDER BY sk_ID, iIndex "
Dim myConnString As String = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=E:\DINDATABASE.mdb;" Dim myConnection As New OdbcConnection(myConnString) Dim myCommand = new OdbcDataAdapter(strSQL, myConnection) Dim myCommand2 = new OdbcDataAdapter(strSQL2, myConnection)
Dim tChk As Integer If sSelected = 0 Then tChk = pSelected End If For Each pRow In ds.Tables("TopCats").Rows Response.Write("<option value=""fmain.aspx?idx=" & iTmpCount & "&pID=" & pRow(0).ToString() & "&iType=" & pRow(2).ToString() & """ ") If tChk = pRow(0) Then Response.Write ("selected=""selected""") End If Response.Write (">" & pRow(3).ToString() & "</option>" & vbCrLf) For Each cRow In pRow.GetChildRows(myDataRelation) Response.Write("<option value=""fmain.aspx?idx=" & iTmpCount & "&pID=" & cRow(1).ToString() & "&sID=" & cRow(0).ToString() & "&iType=" & cRow(2).ToString() & """ ") If sSelected > 0 Then If sSelected = cRow(0) Then Response.Write ("selected=""selected""") End If End If Response.Write ("> " & cRow(3).ToString() & "</option>" & vbCrLf) Next iTmpCount = iTmpCount+1 Next Response.Write ("</select>") Response.Write ("</td></tr>") Response.Write ("</form>") Response.Write ("</table>")
Catch e as Exception Response.Write ("Error") Response.Write ("Exception: " & e.ToString())
End Try End Function
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.