• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 723
  • Last Modified:

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

Hello,

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.
Thanks!
0
austerhaus
Asked:
austerhaus
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
Are you calling a method on the TableAdapter where you need to pass a parameter?

int accountNumber = int.Parse(this.AccountNumber.Text);
adapter.FillByAccountNum(accountNumber);
0
 
austerhausAuthor Commented:
Here is what I have:

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

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?
0
 
Bob LearnedCommented:
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.
0
 
austerhausAuthor Commented:
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?
0
 
Bob LearnedCommented:
If you can't see how Intellisense is useful here, then you need to see how to use it:


DataAdapter-Intellisense.png
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now