If - Datatable condition

3

I need to compare a value of one of the fields of a DataTable , to accomplish a if condition, but I do not know how to do it. below:

 public partial class imp_orcamento : DevExpress.XtraReports.UI.XtraReport
{
    Datatable_orcamento dat_orc = new Datatable_orcamento();

    DataTable ret_orc = new DataTable();

    public imp_orcamento(int id_orc)
    {
        InitializeComponent();

        met_dic_cli(id_orc);
    }

    private void met_dic_cli(int id_orcamento)
    {
        ret_orc = dat_orc.rpt_orcamento(id_orcamento);

        xrLabel1.DataBindings.Add(new XRBinding("Text", ret_orc, "id_orc"));
        xrLabel2.DataBindings.Add(new XRBinding("Text", ret_orc, "data"));
        xrLabel3.DataBindings.Add(new XRBinding("Text", ret_orc, "nome_fantasia"));
        xrLabel6.DataBindings.Add(new XRBinding("Text", ret_orc, "n_doc"));
        xrLabel10.DataBindings.Add(new XRBinding("Text", ret_orc, "tipo_doc"));
        xrLabel12.DataBindings.Add(new XRBinding("Text", ret_orc, "statos"));
        xrLabel13.DataBindings.Add(new XRBinding("Text", ret_orc, "tipo"));
        xrLabel8.DataBindings.Add(new XRBinding("Text", ret_orc, "contato"));
        xrLabel9.DataBindings.Add(new XRBinding("Text", ret_orc, "departamento"));
        xrLabel4.DataBindings.Add(new XRBinding("Text", ret_orc, "vendedor"));
        xrLabel5.DataBindings.Add(new XRBinding("Text", ret_orc, "perfil"));
        xrLabel7.DataBindings.Add(new XRBinding("Text", ret_orc, "tel"));
        xrLabel14.DataBindings.Add(new XRBinding("Text", ret_orc, "val_prop"));
        xrLabel15.DataBindings.Add(new XRBinding("Text", ret_orc, "tp_frete"));
        xrLabel16.DataBindings.Add(new XRBinding("Text", ret_orc, "obs"));
        xrLabel17.DataBindings.Add(new XRBinding("Text", ret_orc, "condicao"));
        xrLabel18.DataBindings.Add(new XRBinding("Text", ret_orc, "modo"));
        if (ret_orc.Columns.Equals("cli_final") != true)
        {
            xrCheckBox1.Checked = true;
        }
    }
    
asked by anonymous 08.08.2016 / 12:47

2 answers

2

Well, I did it, using DataTableReader I'm doing this:

DataTableReader dtr = ret_orc.CreateDataReader();

        if (dtr.HasRows)
        {
            while(dtr.Read())
            {
                string a = dtr["cli_final"].ToString();

                if (a != "0")
                {
                    xrCheckBox1.Checked = true;
                }
            }
        }
    
08.08.2016 / 13:14
1

Another way would be to convert the DataTable ret_orc to an AsEnumerable.

 /// Convert to AsEnumerable
   var qrIn = from row in ret_orc .AsEnumerable()
    select new 
    {
        xrCheckBox1.Checked = dtr["cli_final"].ToString() != "0",
    }
    
08.08.2016 / 14:54