VB 2005, calling a query?

I just started using VB 2005, i want to execute a query i have created when a command button is pressed, any ideas anyone I'm trying to modify an access table using a query, and i've figured all that out only to be left in a dead end with the queriesSad. i can execute the query from the main form (anyform.vb) right someone help please Tongue Tied!!
Thanks everyone, any help you can provide is greatly appreciated
Big Smile


Answer this question

VB 2005, calling a query?

  • Totino

    Hi,


    Yup, you could execute a query in the main form...
    you must further learn on ADO .net to accomplish this.
    Here's an example to get you strated...


    Dim con  as new OleDbConnection

    con.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=yourdbasepath;"
    con.Open()

    Dim com As new OleDbCommand("yourQueryName", con)
    com.ExecuteNonQuery()


    Assuming that your query doesn't return any result set...



    cheers,


    Paul June A. Domag

  • IndianScorpion

  • beautifoolmark

    How about, using VS 2005 and VB.Net

    Alternatively create a query on a table adapter. Call it in line.

    There are two tables, Jobs and Job Details, Parent Child. When the child records change i need to total up the [job details].[Cost] column for a given Foreign Key [job ref] and make an update to the Parent table and relevevant column [jobs].[cost].

    N.B. A trigger would do also.

    Query 1: qrySumCostByJobRef

    SELECT sum(cost) FROM [Job Details] WHERE [job ref]=

    Query 2: qryJobsUpdateCost

    UPDATE Jobs
    SET Cost =
    WHERE ([Job Ref] = )

    Here it is used in code on a saveitem click event:

    Private Sub Job_DetailsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Job_DetailsBindingNavigatorSaveItem.Click

    Me.Validate()

    Me.Job_DetailsBindingSource.EndEdit()

    Me.Job_DetailsTableAdapter.Update(Me.DataDataSet.Job_Details)

    'In line SQL Trigger sum(cost) to parent table

    Dim row As dataDataSet.JobsRow

    row = CType(CType(Me.JobsBindingSource.Current, DataRowView).Row, dataDataSet.JobsRow)

    Me.JobsTableAdapter.qryJobsUpdateCost(Me.Job_DetailsTableAdapter.qrySumCostByJobRef(row.Job_Ref), row.Job_Ref)

    End Sub

    Job Done!


  • VB 2005, calling a query?