Results 1 to 10 of 10

Thread: DataSet Adventures

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    10

    DataSet Adventures

    Hello all,

    I am trying to master the art of using code rather than the design view form components to do this database processing. Since adding the DataAdapter using the design view requires a predefined query, that doesn't seem very realistic!

    I've found an example from planet source code, and I've also found samples in the VS .NET help files. I've copied their techniques to the letter, but I cannot divine why I am getting the following error...

    Error Message: "No value given for one or more required parameters"

    The stack trace is pretty big, I'm not sure what I should type of it that would help to solve the problem, other than pointing out the line.


    Code:
     Try
     
                Dim accessDataAdapter As OleDbDataAdapter = New OleDbDataAdapter()
                accessDataAdapter.TableMappings.Add("Table", "Logins")
    
                '**** Connect to Database ****
    
                accessConnection.Open()
    
                '****  ****
    
                Dim accessSelectCommand As OleDbCommand = _
                New OleDbCommand(selectString, accessConnection)
    
                accessSelectCommand.CommandType = CommandType.Text
                accessDataAdapter.SelectCommand = accessSelectCommand
    
                Dim dsLoginSet As DataSet
                dsLoginSet = New DataSet("Technicians")
    
                ' *** GENERATES EXCEPTION ***
                ' This is the line causing problems
                ' but it's just like the samples....
                accessDataAdapter.Fill(dsloginSet)
    
     ' **** Catch Exception ****
            Catch Ex As System.Exception
                Dim errorD As DialogResult
                errorD = MessageBox.Show(Ex.Message, "Error", _
                        MessageBoxButtons.OK, MessageBoxIcon.Stop)
                errorD = MessageBox.Show(Ex.StackTrace, "Error", _
            MessageBoxButtons.OK, MessageBoxIcon.Stop)
    
     ' **** Always Close Connection ****
            Finally
                accessConnection.Close()
            End Try
            ' ----------------
        End Sub
    Anyone out there wiser than I who could help me determine the source of my problem?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Where is "selectString"?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    10
    Code:
    selectString = "Select T_Login, T_Pass, " _
    & "T_Role From tbl_Technician " _
    & "Where T_Login = " & txtLoginID.Text & _
    " AND T_Pass = " & txtPass.Text & ";"
    Sorry it was defined prior to the code that I had posted. I've gotten yelled at before for posting too much code on a forum so I try to trim it down to the minimum now. ;P

    Gah this is so awful. I've spent days trying to make this kind of stuff work! I beg and plead for merciful help!

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    How about:


    Code:
    selectString = "Select T_Login, T_Pass, " _
    & "T_Role From tbl_Technician " _
    & "Where T_Login = '" & txtLoginID.Text & _
    "' AND T_Pass = '" & txtPass.Text & "';"
    ?


    Note the addition of the single quotes in the code above.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    10
    Wow.

    I was so distressed at all the new kinds of code I didn't even consider that it was the SQL syntax that was throwing a kink into things. Thank you very much!

    Something I'm still pretty confused on though is the DataTable thing... most samples show a DataTable being added. But since I read that "The Tables collection pertaining to the DataSet class lists each of the tables that makes up the DataSet", doesn't that mean that when you fill the DataSet the DataTable object is already created for a table?

    In my code, I've filled the DataSet with a Login, Password, and Role. My textbook only goes into how to bind a control instance to a DataSet. What if I just want to "look" at something? For instance, I'd like to be able to pull the value of Role into a variable so I can deal out priviliges later on based on that role.

    What (if at all) is the syntax for examining that data without binding it?

    Many many many endless thanks!
    <3

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by Monica
    Wow.

    I was so distressed at all the new kinds of code I didn't even consider that it was the SQL syntax that was throwing a kink into things. Thank you very much!
    Don't be distressed. Smoke regularly and you'll never be anxious or distressed ever again, unless you run out.




    Something I'm still pretty confused on though is the DataTable thing... most samples show a DataTable being added.
    Show and example. Or if you don't want to show an example, go over it real slowly.


    But since I read that "The Tables collection pertaining to the DataSet class lists each of the tables that makes up the DataSet", doesn't that mean that when you fill the DataSet the DataTable object is already created for a table?
    Yes, that is correct.


    In my code, I've filled the DataSet with a Login, Password, and Role. My textbook only goes into how to bind a control instance to a DataSet. What if I just want to "look" at something? For instance, I'd like to be able to pull the value of Role into a variable so I can deal out priviliges later on based on that role.
    Now, in the earlier paragraph, you mentioned that a dataset is a collection of tables, and this is true. To access a particular value, you would do something like:

    ds.Tables(0).Rows(4).Item(5).ToString

    OR

    ds.Tables("Doohickey").Rows(4).Item(5).ToString

    So, we're accessing the datatable #0, or the datatable named Doohickey, then going to it's 5th row, and 6th item in that row. Makes sense? To run through this, use a loop!

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    10
    Thank you for explaining that to me

    Lo and behold! Something is actually working now!!!

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Good for you.

    I still can't get a simple MessageBox to work.

  9. #9
    New Member
    Join Date
    Jul 2004
    Posts
    9
    Messagebox.Show ("Hello")

    is the Simplest method for showing a MessageBox...Hihihi

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by tanmoymoitra
    Messagebox.Show ("Hello")

    is the Simplest method for showing a MessageBox...Hihihi
    Thank you. Now I can ask for that raise I always wanted...

Posting Permissions

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



Click Here to Expand Forum to Full Width