mysqlvb.netmysql-function

how to pass parameter to function of mysql through vb.net adapter which is created by query builder wizard


I have this query:

 SELECT * FROM table_1 WHERE (`update_column` = (DATE_SUB(curdate(), INTERVAL 10 DAY)))

It works normally, I want to change 10 day to parameter and pass value of it through adapter, I'm using query builder, with query in adapter:

FillBy_sub_date

Which i want to be like:

 SELECT * FROM table_1 WHERE (`update_column` = (DATE_SUB(curdate(), INTERVAL @_days DAY)))

And i want to pass day value with the following method:

  Me.table_1Adapter.FillBy_sub_date(Me.dataset.table_1, 5) 

5 is the number of day which i wont to pass to query

Problem: when i change number 10 to @_days mysql error showing

Error in list of function arguments: '_days' not recognized. Unable to parse query text.

image


Solution

  • there is more then one way , first create procedure in your mysql database with parameter let call it "return_after_some_days" your query is correct so put it inside procedure

    1. create procedure

      CREATE PROCEDURE return_after_some_day (in param1 INT)
      BEGIN
      SELECT * FROM `table` where `update_column` = (DATE_SUB(curdate(), INTERVAL param1 day  ));
      

      end;

    2. then go to your builder wizard and add query to table adapter

    3. select use existing stored procedure
    4. from list select your procedure name which is (return_after_some_days)
    5. select tabular date and set name of fill method
    6. go inside your code and call your method name from data adapter like

    Me.table_1Adapter.name_of_method_that_call_procedure(Me.dataset.table_1, 5)

    number 5 will be pass to proceuder