locked
Storing a number on a form without showing the number? c# RRS feed

  • Question

  • Hello people

    I want to be able to store a numerical value from my datatable on my form but I don't want to show this number. I understand in order to get the column of the value I need to type "GetValue(2)". 

     

    [code]

    private void NavigateRecords()
            {
                DataRow dRow = ds1.Tables["Workers"].Rows[0];
                textBox1.Text = dRow.ItemArray.GetValue(2).ToString();
            }

    [/code]

    How would I go about storing this numerical value on my form without showing the number in a textbox?


    • Edited by risky14 Monday, October 8, 2012 10:32 AM
    Monday, October 8, 2012 10:32 AM

Answers

  • Declare a member or property like this:

    object mValue;
    
    private void NavigateRecords()
    {
        DataRow dRow = ds1.Tables["Workers"].Rows[0];
        mValue = dRow[2];
    }

    Use a proper type instead of ‘object’.


    • Edited by Viorel_MVP Monday, October 8, 2012 11:58 AM
    • Proposed as answer by Rick van den Bosch Monday, October 8, 2012 12:04 PM
    • Marked as answer by risky14 Tuesday, October 9, 2012 10:06 AM
    Monday, October 8, 2012 11:57 AM

All replies

  • Make the textbox invisible (i.e. set its visible property false)?

    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Monday, October 8, 2012 11:31 AM
  • Declare a member or property like this:

    object mValue;
    
    private void NavigateRecords()
    {
        DataRow dRow = ds1.Tables["Workers"].Rows[0];
        mValue = dRow[2];
    }

    Use a proper type instead of ‘object’.


    • Edited by Viorel_MVP Monday, October 8, 2012 11:58 AM
    • Proposed as answer by Rick van den Bosch Monday, October 8, 2012 12:04 PM
    • Marked as answer by risky14 Tuesday, October 9, 2012 10:06 AM
    Monday, October 8, 2012 11:57 AM
  • Thank you
    Tuesday, October 9, 2012 10:06 AM