How to pass parameter from tbx to tableadapter and return result to different tbx

Posted on 2008-10-22
Last Modified: 2013-11-07

I have a tableadapter with a query that returns a list of customers using an account number as the parameter. What i need is to take a string entered into a textbox (tbxAccountNum) and pass that to the adapter (customersTableAdapter) when an imgbtn gets clicked. The result, I then need to populate into another textbox (tbxCompanyName).

Here is the query from my tableadapter (FillByAccountNum, GetCustomersByAccountNum)
SELECT account_num, company_name, customer_id FROM dbo.customers WHERE (account_num = @account_num)

I am using C#.

Please let me know if any additional information is required.
Question by:austerhaus
  • 3
  • 2
LVL 96

Expert Comment

by:Bob Learned
ID: 22785615
Are you calling a method on the TableAdapter where you need to pass a parameter?

int accountNumber = int.Parse(this.AccountNumber.Text);

Author Comment

ID: 22790501
Here is what I have:

protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e)
        string accountNum = tbxAccountNum.Text;
        customersTableAdapter customersAdapter = new customersTableAdapter();

I had to change "int" to "string" and FillByAccountNum gives the error: No overload for method 'FillByAccountNum' takes '1' arguments. Is what I have thus far correct?

If so: How do I assign the value returned to tbxCustomerName?
LVL 96

Expert Comment

by:Bob Learned
ID: 22790577
The Intellisense should give you an understanding of what you need to do.  GetCustomersByAccountNum is a function with a return, that you are ignoring in this case.  You need to look and see what the return type is and assign the return value to the TextBox.

Author Comment

ID: 22831881
Thanks but intellisense is of little help. What is the "vanilla" way to pass a parameter to a datatable, obtain the response and assign that value to a textbox?
LVL 96

Accepted Solution

Bob Learned earned 500 total points
ID: 22832442
If you can't see how Intellisense is useful here, then you need to see how to use it:


Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

825 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