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
Solved

Selecting data by code into a tableadapter

Posted on 2007-12-06
1
292 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 31
Upgrading my SSIS package in VS 2012 6 59
Finding Events logs for IIS website that restarts 2 14
SSRS Deployment problem 5 65
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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:…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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