Link to home
Start Free TrialLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

Text field from SQL has no value inside code C#

I need to make a decision on this field: this.txtJOBNMBRFROM - this is  text box on my form
This field gets its value from a SQL statement. When the screen appears all the values are there. My if statement does not work because the string is blank inside the code. What am I missing?

DataCommand.CommandText = "select top 1 JOBNUMBER,CASE WHEN XFRTOJOB = '' THEN 'NO TRANSFER' ELSE XFRTOJOB END AS XFRTOJOB from job_linker where transnmbr='" + VoucherNumber + "' and len(rtrim(jobnumber))>0";

                DataDataAdapter = new System.Data.SqlClient.SqlDataAdapter();
                DataDataAdapter.SelectCommand = DataCommand;
                DataDataAdapter.TableMappings.Add("Table", "JOBNUMBER");

                DataDataAdapter.Fill(DataDataSet);
                if (DataDataSet == null || (DataDataSet.Tables.Count == 0) || (DataDataSet.Tables[0].Rows.Count == 0))
                {
                    MessageBox.Show("No job found for this payment in Job Linker. Please return to Inquiry->Purchasing->Transaction By Vendor and enter a job on this payment.");
                    /* Dispose of the connection */
                    GPConnObj = null;

                    /* Shutdown the connection */
                    resp = GPConnection.Shutdown();
                    DataConnection.Close();
                    this.Hide();
                    this.Dispose();
                }

                this.txtJOBNMBRORIG.DataBindings.Add("Text", DataDataSet.Tables["JOBNUMBER"], "JOBNUMBER").ToString();
                this.txtJOBNMBRORIG.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;

                this.txtJOBNMBRFROM.DataBindings.Add("Text", DataDataSet.Tables["JOBNUMBER"], "XFRTOJOB").ToString();
                this.txtJOBNMBRFROM.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;

                mystring = this.txtJOBNMBRFROM.Text.ToString();

                MessageBox.Show(mystring + " The length is " + mystring.Length);
-------------------Here is the IF statement -----------------------------------------------------------
                if (this.txtJOBNMBRFROM.Text == "NO TRANSFER")
                {
                    this.txtJOBNMBRTO.DataBindings.Add("Text", DataDataSet.Tables["JOBNUMBER"], "JOBNUMBER").ToString();
                }
                else
                {
                    this.txtJOBNMBRTO.DataBindings.Add("Text", DataDataSet.Tables["JOBNUMBER"], "XFRTOJOB").ToString();
                }
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rwheeler23

ASKER

I also moved this code to the form shown event and that fixed it as well.