Solved

Selecting data by code into a tableadapter

Posted on 2007-12-06
1
289 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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now