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();
                }
LVL 1
rwheeler23Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
I think the SQL connection object is missing. Assuming that this connection is called SQlConn please replace
                 DataDataAdapter = new System.Data.SqlClient.SqlDataAdapter();
                 DataDataAdapter.SelectCommand = DataCommand;
                 DataDataAdapter.TableMappings.Add("Table", "JOBNUMBER");

                 DataDataAdapter.Fill(DataDataSet);

Open in new window

with:
string queryString = 
  "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";
SqlDataAdapter adapter = new SqlDataAdapter(queryString, SQlConn);
DataDataSet = new DataSet();
adapter.Fill(DataDataSet);

Open in new window


Notice that you only have one table in the dataset, you can access via DataDataSet.Tables[0]. Also make sure you SQL statement is correct.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwheeler23Author Commented:
I also moved this code to the form shown event and that fixed it as well.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.