|
-
Sep 14th, 2007, 03:14 PM
#1
Thread Starter
Lively Member
[RESOLVED] Passing parameters to a table adapter
I have a tableadapter set up with the following select command:
vb Code:
SELECT GameIndex, MatchNumber
WHERE GameIndex = ? AND MatchNumber = ?
The parameters GameIndex and MatchNumber show up in the SelectCommand.parameters collection for the tableadapter, but when I try to provide the parameters with data using this code:
vb Code:
Tbl_GreenMatchDataTableAdapter.SelectCommand.Parameters(0).Value = 1
I get the error message that the “SelectCommand is not a member of…” that table adapter. I have seen this format for providing table adapters parameters in other threads.
Any suggestions on where I have gone astray?
-
Sep 15th, 2007, 03:04 AM
#2
Re: Passing parameters to a table adapter
You don't set TableAdapter parameters like that. When you add a query to a TableAdapter it is executed via a method of that TableAdapter class. Usually your default query will have no parameters and will be executed by calling Fill or GetData. If you add a query that has parameters for the GameIndex and MatchNumber columns then new methods are added to the TableAdapter and you are prompted for names for them. If you're filtering on the GameIndex and MatchNumber then you should be naming them FillByGameIndexMatchNumber and GetDataByGameIndexMatchNumber. Those two methods will each have two arguments, named GameIndex and MatchNumber. THAT is where you set the parameter values: by passing them to those methods when you call them, e.g.
vb.net Code:
myTableAdapter.FillByGameIndexMathcNumber(myDataTable, gameIndexValue, matchNumberValue)
How do I know all this? Because I went to the MSDN library and read about TableAdapters. You should too.
-
Sep 15th, 2007, 10:29 AM
#3
Thread Starter
Lively Member
Re: Passing parameters to a table adapter
Thanks for the information.
Before posting, I spent over six straight hours in the MSDN library on this subject, following threads left by you and others. I spend another 3 or 4 hours reading every post in this forum that had the word adapter in it (which is where I got the erroneous table adapter method by the way), so mine if not for the lack of trying. Sometime late last night I started figuring it out and managed to make some head way on my project (using another of your posts). My point- the MSDN library never once laid it out like you just did. If it is there, it is not left in an intuitive spot and I believe I read every article on table adapters.
Anyway, I am very thankful that you and others take the time to help out those of us who are going through a very painful learning process.
Cheers
-
Sep 15th, 2007, 08:03 PM
#4
Re: [RESOLVED] Passing parameters to a table adapter
This is the main topic dedicated to TableAdapters on MSDN. It is the fifth match returned by an MSDN search for tableadapters. The seventh topic link on that page is entitled "How to: Create TableAdapter Queries" and it answers your question.
-
Sep 16th, 2007, 09:13 AM
#5
Thread Starter
Lively Member
Re: [RESOLVED] Passing parameters to a table adapter
Ok- going back and re-reading the article it is obvious that while I was reading the articles, they were not making since to me. I was trying too hard to find something that looked like the incorrect method I found in this forum. Today, while I am more refreshed, it makes a whole lot more since. Thanks for taking the time and not giving up on this frazzled VB newbie.
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
|