Results 1 to 5 of 5

Thread: [RESOLVED] Passing parameters to a table adapter

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Resolved [RESOLVED] Passing parameters to a table adapter

    I have a tableadapter set up with the following select command:

    vb Code:
    1. SELECT GameIndex, MatchNumber
    2. 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:
    1. 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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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:
    1. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Thumbs up 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
  •  



Click Here to Expand Forum to Full Width