PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2017 [RESOLVED] Fill based on value-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] Fill based on value

  1. #1

    Thread Starter
    Fanatic Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    778

    Resolved [RESOLVED] Fill based on value

    Hi am not sure how to word this question....

    When user login I store that CustomerID in Globalvariable. Then on my form I have e.g.:

    Customer Details (textboxes) --> Orders (Datagridview)

    I have to admit that with new generation software I have be spoiled because I just drag datasources to form... This means that ALL data is loaded and I just browse to customer I want. But now I am trying to improve on this. I only want to load customer records based on that CustomerID..

    So for the customers TableAdapter I modify SELECT to include a WHERE statement:

    Code:
    SELECT CustomerID, CustomerName
    FROM tblCustomers
    WHERE (CustomerID = 1)
    This works perfect..... for customerID 1... But now Customer 2 logs in and that ID is stored in Globalvariable. So my question is this: How can I get that ID from Globalvariable into my WHERE statement?

    Thanks
    Last edited by schoemr; Feb 28th, 2018 at 01:43 AM.
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,760

    Re: Fill based on value

    Don't modify the default query. Add a new query to the same table adapter, which will add new methods to execute that query. If you want to filter data by CustomerID, you would name the methods FillByCustomerID and GetDataByCustomerID. After that, this code will get all the data:
    vb.net Code:
    1. myTableAdapter.Fill(myDataSet.Customers)
    and this code will get only data for that ID:
    vb.net Code:
    1. myTableAdapter.FillByCustomerID(myDataSet.Customers, customerID)
    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
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,760

    Re: Fill based on value

    Note that, when you add the query, you don't put a value in the SQL code but rather a parameter. Depending on the database, you might use a named parameter:
    sql Code:
    1. WHERE CustomerID = @CustomerID
    or an unnamed parameter:
    sql Code:
    1. WHERE CustomerID = ?
    That will then add a parameter to the command object inside the table adapter and that is mapped to a parameter on the FillByCustomerID method.
    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

  4. #4

    Thread Starter
    Fanatic Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    778

    Re: Fill based on value

    Got it , thanks JMC
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,760

    Re: [RESOLVED] Fill based on value

    If you're going to use typed DataSets, I would suggest doing some reading on table adapters.

    https://msdn.microsoft.com/en-us/library/7zt3ycf2.aspx

    It's a subject that a lot of people, including many experienced developers, don't know a lot about and end up doing or recommending bad things as a result.
    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

  6. #6

    Thread Starter
    Fanatic Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    778

    Re: [RESOLVED] Fill based on value

    Okay I will do that, thank you
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width