Solved

Selecting data by code into a tableadapter

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

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 - Not Sure if Multi-threading is What I Need 4 39
DataGridView / get bound table name? 8 36
SSIS Start 2 38
vb.net deleting excel sheet in workbook 11 30
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:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…

762 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