If - Datatable condition

Asked

Viewed 165 times

3

I need to compare a value of one of the fields of a DataTable, to fulfil a condition if, but I don’t know how to do it. follow 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;
        }
    }
  • managed to solve his problem?

2 answers

2


Guys, I did it, using DataTableReader I’m doing like this:

DataTableReader dtr = ret_orc.CreateDataReader();

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

                if (a != "0")
                {
                    xrCheckBox1.Checked = true;
                }
            }
        }
  • 1

    Thomas, if you had any doubts about that it would be better to open another question.

  • 1

    Or edit the question by putting this code and change it by asking if it’s correct. While there are no answers, it is possible to modify the question (then you can only invalidate the existing answers.

  • Ok. As there are already answers, I’ll leave it as is. editing my reply.. thank you.

1

Another way would be to contact the ret_orc Datatable for an Asenumerable.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.