Solved

Selecting data by code into a tableadapter

Posted on 2007-12-06
1
291 Views
Last Modified: 2013-11-26
I have generated a quick sample program which works fine:-
Public Class Form1

    Private Sub AdmasBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.AdmasBindingSource.EndEdit()
        Me.AdmasTableAdapter.Update(Me.PIComtass02DataSet.Admas)

    End Sub


    Private Sub AdmasBindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdmasBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.AdmasBindingSource.EndEdit()
        Me.AdmasTableAdapter.Update(Me.PIComtass02DataSet.Admas)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
.

        Me.PlmasTableAdapter.Fill(Me.PIComtass02DataSet.Plmas)
              Me.AdmasTableAdapter.Fill(Me.PIComtass02DataSet.Admas)

    End Sub
End Class

This brings a complete list in which I can page through. What I need to be able to do is change the input query to select a single record by adding a " WHERE AccountNo = " condition to the select statement in the program.
Any ideas?
0
Comment
Question by:grwallace
1 Comment
 
LVL 27

Accepted Solution

by:
VBRocks earned 500 total points
ID: 20420379
I think you'll have to use a DataAdapter to accomplish this.

Open the DataSet designer, and on the AdmasTable, right-click and go to "Configure".
A "TableAdapter Configuration Wizard" should open up.  There you will find your SQL Select Statement.

Now from here, you can do 3 things:
    Option 1  (Edit Syntax)
        Add your WHERE clause to the SQL SELECT syntax here.
        Click "Finish"

    Option 2  (Query Builder)
        Click on the "Query Builder..." button.
        Find the column that you want to add a WHERE clause (filter) to, and enter your filter in the "Filter"
            column.
        Click the "Execute Query" button to verify your results.
        Click the "OK" button, and then the "Finish" button.

    Option 3  (DataAdapter)
         Copy the SQL SELECT syntax.
         Go to your code, and then add lines to use a DataAdapter, as demonstrated:
        Dim AdmasTableAdapter As New _Table1TableAdapters.table1TableAdapter()

        'Use this to set your account number
        Dim AccountNo As Int32 = 0

        'Paste the SQL SELECT string here, and add the WHERE clause:
        Dim SQL As String = "SELECT * FROM Admas WHERE AccountNo=" & AccountNo

        'Create and us a DataAdapter to fill your table
        '  *** NOTE:  If this is an SQL Server database, use the SQLClient namespace instead ***
        Dim adapter As New OleDb.OleDbDataAdapter(SQL, _
            AdmasTableAdapter.Connection.ConnectionString)

        'SQL Server code:
        'Dim adapter As New SqlClient.SqlDataAdapter(SQL, _
        '    AdmasTableAdapter.Connection.ConnectionString)

        adapter.Fill(Me.PIComtass02DataSet.Admas)

        adapter.Dispose()
         
   
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question