none
How To Pass A Parameter To A TableAdapter - VB 2019 RRS feed

  • Question

  • Hi:

    I have a simple TableAdapter query to fill a dataset. The query has a parameter "Param1". I cannot

    figure out how to pass a value from a "Form" into "Param1". I am using an MSAcess databse and oledb.

    I have spent the last two days researching but nothing works so far.

    Here is the query:

    SELECT SE_KEY, SE_NAME, SE_ST, SE_JT, SE_CTRY, SE_TIER3, SE_TIER3_T, SE_TIER2, SE_TIER2_T, SE_TIER1, SE_TIER1_T, SE_URL, SE_AM, SE_AP, SE_AT, SE_CS, SE_FTC, SE_FRC, SE_CG, SE_CD, SE_CC, SE_CO, SE_EQ, SE_FA, SE_GA, SE_OR1, SE_OR2, SE_OR3, SE_OR4, SE_OR5, SE_OR6, SE_RA, SE_SH, SE_TA, SE_TG, SE_TE, SE_VE, SE_E_DATE, SE_R_DATE FROM SE WHERE TIER3 = ?

    Here is the code in my form:

         

    Option Explicit On
    Option Strict On

    Imports System.Data
    Imports System.Reflection
    Imports System.Data.OleDb

    Public Class FrmRpt_SE_2

        Private Sub FrmRpt_SE_2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

            Dim ds As New PSBDataSet
            Dim ad As New PSBDataSetTableAdapters.SETableAdapter

            Dim param As OleDbParameter = New OleDbParameter With {
                .ParameterName = "Param1",
                .OleDbType = OleDbType.VarChar,
                .Direction = ParameterDirection.Input,
                .Value = "?"}

            ad.oledparameters.Add(param)


            ad.GetDataByTier3(ds.SE)

            Dim rpt As New CrystalReport_SE_1
            rpt.SetDataSource(ds)
            CrystalReportViewer1.ReportSource = rpt

        End Sub

    End Class

    I would really appreciate some help. Thanks.




    Sunday, May 31, 2020 4:46 PM

Answers

  • Here is an example where I want to get specific products by a category identifier.

    Give useful names 

    I add a ComboBox for categories and gets populated in form load

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.CategoriesTableAdapter.Fill(Database1DataSet.Categories)
    End Sub

    Place a button on the form to get the select category from the ComboBox and use the value member which is the key to fetch all products for that category.

    Private Sub SelectProductsForCategoryButton_Click(sender As Object, e As EventArgs) _
        Handles SelectProductsForCategoryButton.Click
    
        ProductsTableAdapter.
            FillByCategoryIdentifier(
                Database1DataSet.Products, CInt(CategoriesComboBox.SelectedValue))
    End Sub

     

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, May 31, 2020 10:15 PM
    Moderator

All replies

  • 'Dim param As OleDbParameter = New OleDbParameter With {
    '            .ParameterName = "Param1",
    '            .OleDbType = OleDbType.VarChar,
    '            .Direction = ParameterDirection.Input,
    '            .Value = "?"}

            ad.oledparameters.AddWithValue("?","Param1")

    Success
    Cor

    Sunday, May 31, 2020 8:52 PM
  • It says that an argument is not specified for parameter "Param1" and the

    GetDataByTier3 is underlined in red. Not sure what it is looking for.


    Sunday, May 31, 2020 9:29 PM
  • Yea it can not work in the air. 

    Somehow you should have set everything with the tool in this part. 

    PSBDataSetTableAdapters.SETableAdapter

    There should be a table adapter which has the right connection and the method GetDataByTier which contains the select string you show. 


    Success
    Cor

    Sunday, May 31, 2020 9:44 PM
  • The whole thing works if you remove the parameter stuff. So the connection, tableadapter etc. is good.
    Sunday, May 31, 2020 9:47 PM
  • Here is an example where I want to get specific products by a category identifier.

    Give useful names 

    I add a ComboBox for categories and gets populated in form load

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.CategoriesTableAdapter.Fill(Database1DataSet.Categories)
    End Sub

    Place a button on the form to get the select category from the ComboBox and use the value member which is the key to fetch all products for that category.

    Private Sub SelectProductsForCategoryButton_Click(sender As Object, e As EventArgs) _
        Handles SelectProductsForCategoryButton.Click
    
        ProductsTableAdapter.
            FillByCategoryIdentifier(
                Database1DataSet.Products, CInt(CategoriesComboBox.SelectedValue))
    End Sub

     

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, May 31, 2020 10:15 PM
    Moderator
  • Hi Karen:

    Thanks you so much. It works beautifully. 😊

    Sunday, May 31, 2020 11:19 PM