Solved

Selecting data by code into a tableadapter

Posted on 2007-12-06
1
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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