VS 2008 C# text field value into string variable.

rwheeler23
rwheeler23 used Ask the Experts™
on
I have a text field on a form called txtDocType. In the database the value is actualy an integer value rangng from 1-9. I have a case statement that converts the number to 1-Sales, 2-Order, 3-Quote , etc. The string value displays correctly on the screen. Now I also have a string variable called TranType. I simply want to assign the value of txtDocType to the string varialble TranType. I thought this would do the trick:

TranType = txtDocType.Text;
So the values of TranType will be Invoice, Order, Quote, etc.
The value for TranType is always null. What am I missing here?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Please be more explicit about your data types.  For example, does 1-Sales refer to a string, such as "1-Sales" or "Sales", or is it the integer 1 or the string "1", or is it an enum of some sort?  What exactly, do you have at each stage, and what exactly do you want?
Top Expert 2013

Commented:
Set breakpoints in your code to see what is the value of txtDocType.Text when :
TranType = txtDocType.Text; is executed.
Check if your TranType value is overwritten somewhere....
rwheeler23President

Author

Commented:
Here is the code. In the database the field for trxtype is an integer. I convert that to a string equivalent using a case statement. If you look at my code below you will see where I commented out my original line and hard coded in Transactiontype='Sales-Invoice". When I do this my stored procedure correctly deletes the records. The line TransactionType = txtDocumentType.Text.Trim(); should give me the same result. I added a message box in my sp call to show me all fields and I see the correct value. Unless the TRIM function is not working I cannot figure out why the records do not delete when the TransactionType field is included in the delete statement.
public frmClearJobLinker()
        {
            InitializeComponent();

            /* Get document information for Cash Receipts Entry */
            if (RmCashDistributionWindow.IsOpen)
            {
                BatchSource = RmCashReceiptsWindow.BatchSource;
                DocumentNumber = RmCashReceiptsWindow.DocumentNumber;
                TransactionType = "Payment";
                txtDocumentNumber.Text = RmCashReceiptsWindow.DocumentNumber;
            }

            /* Get document information for sales transaction entry */
            if (RmSalesDistributionWindow.IsOpen)
            {
                BatchSource = RmSalesEntryWindow.BatchSource;
                DocumentNumber = RmSalesEntryWindow.RmDocumentNumberWork;
                switch (RmSalesEntryWindow.DocumentType.Value.ToString())
                {
                    case "1":
                        txtDocumentType.Text = "Sales-Invoices";
                        break;
                    case "2":
                        txtDocumentType.Text = "Debit Memos";
                        break;
                    case "3":
                        txtDocumentType.Text = "Finance Charges";
                        break;
                    case "4":
                        txtDocumentType.Text = "Service-Repairs";
                        break;
                    case "5":
                        txtDocumentType.Text = "Warranty";
                        break;
                    case "6":
                        txtDocumentType.Text = "Credit Memo";
                        break;
                    case "7":
                        txtDocumentType.Text = "Returns";
                        break;
                    default:
                        txtDocumentType.Text = "Unknown";
                        break;
                }
                txtDocumentNumber.Text = RmSalesEntryWindow.RmDocumentNumberWork;
                /* TransactionType = txtDocumentType.Text.Trim() ; */
                TransactionType = "Sales-Invoice";
                
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Dispose();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            /* Clear Job Linker table based on this batch source,transaction number and trx type */
            try
            {
                SqlConnection con = GetConnection();
                SqlCommand cmd = new SqlCommand();

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@BCHSOURC", BatchSource));
                cmd.Parameters.Add(new SqlParameter("@DCMTNMBR", DocumentNumber));
                cmd.Parameters.Add(new SqlParameter("@TRXTYPE", TransactionType));
                MessageBox.Show(BatchSource);
                MessageBox.Show(DocumentNumber);
                MessageBox.Show(TransactionType);

               
                cmd.CommandText = "rbsClearJobLinker";

                cmd.Connection = con;

                cmd.ExecuteNonQuery();

                con.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR::" + ex.Message);
                this.Close();

            }

            this.Hide();
            this.Dispose();
        }

        private SqlConnection GetConnection()
        {
            /* Create reader and open file containing connection string */
            TextReader tr = new StreamReader(@"C:\Program Files\Microsoft Dynamics\GP\Addins\GSE.INI");

            /* Read line containing the connection string */
            ConnectionString = tr.ReadLine();

            /* Close the stream */
            tr.Close();

            DataConnection = new System.Data.SqlClient.SqlConnection(ConnectionString);
            DataConnection.Open();

            return DataConnection;
        }

Open in new window

Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Top Expert 2013
Commented:
just wondering if it is a typo:
Sales-Invoice and Sales-Invoices ?
Commented:
In line 22, you have "Sales-Invoices", while in line 48, you have "Sales-Invoice" (ie, no "s" at the end).  Perhaps this is causing your problem.
rwheeler23President

Author

Commented:
We all noticed the same thing at the same time. Working 24 x 7 does this to you. Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial