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

C# -- TableAdapter -- "GetDataBy" Column Value ?

Running the attached 1.jpg via DataSet1.xsd works.

Running the below gets the attached 2.jpg
        private void iTEM_NUMTextBox_Leave(object sender, EventArgs e)
        {
            MessageBox.Show("leaving");
            this.iM_IDTextBox.Text = this.gML_ITEMMSTRTableAdapter.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).IDColumn.ToString();
        }
---------------------------------------------------
How can I change the above
GetDataBy__StockNumber(iTEM_NUMTextBox.Text).
IDColumn.ToString(); so it displays the actual
ID #177982 (like attached 1.jpg) instead of
displaying the word "ID" (like attached 2.jpg) ?
1.jpg
2.jpg
0
finance_teacher
Asked:
finance_teacher
  • 6
  • 5
1 Solution
 
BIOGENIUSCommented:
do you want to get_data_by_Id or do you want to use the same getdataby_Stocknumber to return ID?
0
 
finance_teacherAuthor Commented:
I want to use getdataby_Stocknumber (or whatever you think is easiest)

Example
 1. user enters ITEM NUM
 2. clicks TAB
 3. IM ID populates based on "ID" column of "getdataby_Stocknumber" results
0
 
finance_teacherAuthor Commented:
Please help
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
BIOGENIUSCommented:
it seems that this textbox is not bounded to the column ID so you have two ways:
1) delete it and its label then drag them again from datasource box and drop them on the form.
2) bind them manualy by select the textbox an goto properties-> data->select the dataSource as the tableadapter, select Displaymember as ID, Select VaueMember as ID
0
 
finance_teacherAuthor Commented:
Still fails, also I don't have the Displaymember / VaueMember  options on these two fields (attached)

Steps I did:
 1. created a new form
 2. dropped DataSources WINDOW,
    GML_ROITEM onto form, includes
    ITEM_NUM and IM_ID fields
 3. readded below
        private void iTEM_NUMTextBox_Leave(object sender, EventArgs e)
        {
            MessageBox.Show("leaving");
            this.iM_IDTextBox.Text = this.gML_ITEMMSTRTableAdapter.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).IDColumn.ToString();
        }
 4. ran this NEW form
 5. get same error
0001.jpg
0002.jpg
0
 
BIOGENIUSCommented:
please put abreake point in that line:
this.iM_IDTextBox.Text = this.gML_ITEMMSTRTableAdapter.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).IDColumn.ToString();
 and tell me what you got about that part:
 this.gML_ITEMMSTRTableAdapter.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).IDColumn.ToString();

0
 
finance_teacherAuthor Commented:
Attached is my autos window.

I see "Test 11" when hovering over "(iTEM_NUMTextBox.Text)"
but see nothing when hovering over "ToString".

What other info would you like ?
0003.jpg
0
 
BIOGENIUSCommented:
try this:
this.iM_IDTextBox.Text = this.gML_ITEMMSTRTableAdapter.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).Rows[0][ID].ToString();

0
 
finance_teacherAuthor Commented:
I am using .net 2.0 and below fails
----------------------------------------------------------
Below works, but gives RUNTIME error
     --> "There is no row at position 0"
if there are no results

How can I fix ?
----------------------------------------------------------
        private void iTEM_NUMTextBox_Leave(object sender, EventArgs e)
        {
            if (this.gmL_ITEMMSTRTableAdapter1.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).Rows[0]["ID"].ToString().Length > 0)
            {
                this.iM_IDTextBox.Text = this.gmL_ITEMMSTRTableAdapter1.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).Rows[0]["ID"].ToString();
            }
        }
0
 
BIOGENIUSCommented:
change it to be
 private void iTEM_NUMTextBox_Leave(object sender, EventArgs e)
        {
            if (this.gmL_ITEMMSTRTableAdapter1.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).Rows.Count> 0)
            {
                this.iM_IDTextBox.Text = this.gmL_ITEMMSTRTableAdapter1.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).Rows[0]["ID"].ToString();
            }
        }
 
or simply you can put it in a try catch statment like:

 private void iTEM_NUMTextBox_Leave(object sender, EventArgs e)
        {
            try
            {
                this.iM_IDTextBox.Text = this.gmL_ITEMMSTRTableAdapter1.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).Rows[0]["ID"].ToString();
            }
catch
{
}
        }  
0
 
finance_teacherAuthor Commented:
Thanks, the below work great
---------------------------------------------------------------------
        private void iTEM_NUMTextBox_Leave(object sender, EventArgs e)
        {
            if (this.gmL_ITEMMSTRTableAdapter1.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).Rows.Count > 0)
            {
                this.iM_IDTextBox.Text = this.gmL_ITEMMSTRTableAdapter1.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).Rows[0]["ID"].ToString();
            }
        }
---------------------------------------------------------------------
        private void iTEM_NUMTextBox_Leave(object sender, EventArgs e)
        {
            try
            {
                this.iM_IDTextBox.Text = this.gmL_ITEMMSTRTableAdapter1.GetDataBy__StockNumber(iTEM_NUMTextBox.Text).Rows[0]["ID"].ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("No match found");
            }
        }
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now