how to fill checkbox from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RomeoX
    New Member
    • Jan 2010
    • 25

    how to fill checkbox from database

    Dear there,

    Actually I would like to populate or fill my checkbox from data from database. How can I do it? The data in DB table attribute is "Status" so either 1 or 0 if it's 1 Select the checkbox. I have Window Form.

    Here is my code:
    Code:
    private void bringdata()
            {
                // select a data
                SQL = "SELECT * FROM trafic";
                // command phrase
                cmd = new OracleCommand(SQL, conn);
                cmd.CommandType = CommandType.Text;
                xx = cmd.ExecuteReader();
                if (xx.Read())
                {
                   
                    readdata();
                   
                }
    
                
            }
    
    
    
            private void readdata()
            {
                this.textBox3.Text = Convert.ToString(xx["id"]);
                this.textBox1.Text = Convert.ToString(xx["comp_name"]);
                this.textBox2.Text = Convert.ToString(xx["comp_type"]);
                this.richTextBox1.Text = Convert.ToString(xx["describe"]);
                
                
                this.checkBox1.Text = Convert.ToString(xx["status"]);
                
                
                 
            }
    
    
            private void Create_user_Load(object sender, EventArgs e)
            {
                string oradb = "Data Source=XE;User Id=hr;Password=hr;";
                conn = new OracleConnection(oradb);
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                bringdata();
    
                this.Refresh();
    
    
            }

    Thank in advance.
  • Dody
    New Member
    • Aug 2011
    • 11

    #2
    hi remox,
    Code:
    'as i understand this line 
    
    this.checkBox1.Text = Convert.ToString(xx["status"]);
    
    'i think it must be
    
    if xx["status"]=0
       this.checkBox1.Checked=false
    else
       this.checkBox1.Checked=true
    end if

    Comment

    Working...