Question : 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) ?

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

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

{

}
       }  

Random Solutions  
 
programming4us programming4us