1. #1
    Bram's Avatar
    Registered
    01/08/02
    Location
    Gent
    Posts
    9,675
    iTrader
    3 (100%)
    Mentioned
    0 Post(s)
    Reputation
    0/361

    Rij selecteren in DataSet geeft fout via .find

    Ik was vandaag bezig met een oefening asp.net (vrijdag examen van), maar kwam iets vreemds tegen.
    In de een oefening wordt gevraagd om een bestelformulier te maken. In dat formulier zit een keuzelijstje met alle artikels, als je een keuze maakt, dan wordt de prijs weergegeven van dat artikel in een label.

    Eerder in de code had ik een dataset al gevuld met alle artikels en dacht dat het maar een kwestie zou zijn van
    Code:
    objDS.Tables(0).Rows.Find(ddlArtikels.SelectedValue)
    te gebruiken om de juiste rij te selecteren. Ik kreeg hier echter de foutmelding "Table doesn't have a primary key.". Ik controleerde dit in Access (oefening draait op een .mdb bestand) en zag wel degelijk een primary key ingesteld staan.

    Ik heb het probleem nu zo opgelost:
    Code:
                Dim sqlArtikel As String = "SELECT * FROM tblBrillen WHERE brilID = " & ddlArtikels.SelectedValue
                Dim objDA2 As New System.Data.OleDb.OleDbDataAdapter(sqlArtikel, cnnConnection)
                Dim objDS2 As New System.Data.DataSet
                objDA2.Fill(objDS2)
    
                Dim objDT As System.Data.DataTable = objDS2.Tables(0)
                Dim objRC As System.Data.DataRowCollection
    
                objRC = objDT.Rows
    
                Dim row As System.Data.DataRow = objRC.Item(0)
                Dim strPrijs As String = row("prijs")
    
                lblPrijs.Text = strPrijs
    Het werkt perfect, maar het is zo omslachtig. Mss zijn er nog andere manieren om het te doen, maar onze cursus asp.net was maar heel beknopt.
    Last edited by Bram; 07-01-2009 at 20:50.
    If I had a nickel for every time someone told me that my idea for melting down coins to make a giant robotic parrot was a bad idea, I would have one kicka$$ giant robotic parrot.
    no votes  

  2. #2
    Cycloon's Avatar
    Registered
    18/01/04
    Location
    Melle
    Posts
    10,535
    iTrader
    56 (100%)
    Mentioned
    0 Post(s)
    Reputation
    27/102
    Je moet ook je adapter instellen om de keys door te geven aan de dataset.

    Code:
    objDA2.MissingSchemaAction = MissingSchemaAction.AddWithKey;
    dan kan je die find wel gebruiken.
    “In terms of how we evaluate schooling, everything is about working by yourself. If you work with someone else, it’s called cheating. Once you get out in the real world, everything you do involves working with other people.”
    PSN: Cycloon - Final Fantasy XIV: A realm reborn character
    no votes  

  3. #3
    Bram's Avatar
    Registered
    01/08/02
    Location
    Gent
    Posts
    9,675
    iTrader
    3 (100%)
    Mentioned
    0 Post(s)
    Reputation
    0/361
    Code:
    Dim strSql As String = "SELECT * FROM tblBrillen"
            Dim objDA As New System.Data.OleDb.OleDbDataAdapter(strSql, cnnConnection)
            Dim objDS As New System.Data.DataSet
    
            objDA.Fill(objDS)
            objDA.MissingSchemaAction = Data.MissingSchemaAction.AddWithKey
    Ik krijg nog altijd dezelfde fout, of hebbek da lijntje ergens verkeerd gezet?

    edit: nvm, moet natuurlijk voor de Fill staan...

    bedankt voor het snelle antwoord. waarom doet em da feitelijk niet automatisch???
    If I had a nickel for every time someone told me that my idea for melting down coins to make a giant robotic parrot was a bad idea, I would have one kicka$$ giant robotic parrot.
    no votes  

  4. #4
    Cycloon's Avatar
    Registered
    18/01/04
    Location
    Melle
    Posts
    10,535
    iTrader
    56 (100%)
    Mentioned
    0 Post(s)
    Reputation
    27/102
    Dat lijntje moet natuurlijk komen op een plaats voor je je dataset opvult. De laatste en voorlaatste regel dus wisselen.
    “In terms of how we evaluate schooling, everything is about working by yourself. If you work with someone else, it’s called cheating. Once you get out in the real world, everything you do involves working with other people.”
    PSN: Cycloon - Final Fantasy XIV: A realm reborn character
    no votes  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in