|
-
Jul 28th, 2004, 10:14 AM
#1
Thread Starter
New Member
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?
-
Jul 28th, 2004, 10:36 AM
#2
-
Jul 28th, 2004, 10:43 AM
#3
Thread Starter
New Member
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!
-
Jul 28th, 2004, 10:55 AM
#4
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.
-
Jul 28th, 2004, 11:39 AM
#5
Thread Starter
New Member
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
-
Jul 28th, 2004, 12:28 PM
#6
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!
-
Jul 28th, 2004, 01:03 PM
#7
Thread Starter
New Member
Thank you for explaining that to me 
Lo and behold! Something is actually working now!!!
-
Jul 28th, 2004, 11:20 PM
#8
Good for you.
I still can't get a simple MessageBox to work.
-
Jul 29th, 2004, 12:08 AM
#9
New Member
Messagebox.Show ("Hello")
is the Simplest method for showing a MessageBox...Hihihi
-
Jul 29th, 2004, 12:26 AM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|