我如何验证来自linq的数据过滤 [英] How van I validate filtering of data from linq

查看:86
本文介绍了我如何验证来自linq的数据过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请我尝试验证数据过滤。这是我在下面使用的方法,但它不起作用而是继续显示Enter Details。

Please i tried to validate filtering of data. This is the method i used below but it didn't work instead it keeps showing Enter Details.

private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != String.Empty && comboBox1.SelectedText != String.Empty)
            {
                var res = from result in ds.Results where result.REGISTRATION_NUMBER == textBox1.Text && result.EXAM_YR == comboBox1.SelectedItem select result;
                if (res != null)
                    resultBindingSource1.DataSource = res;
                else
                    MessageBox.Show("no data found");
            }
            else
            {
                MessageBox.Show("Enter details");
            }
        }

推荐答案

也许尝试替换
result.EXAM_YR == comboBox1.SelectedItem

result.EXAM_YR == comboBox1.SelectedText





:ThePhantomUpvoter的评论是正确的;如果您收到输入详细信息消息,则表示textBox1.Text为空或comboBox1.SelectedText为空。我会去comboBox1.SelectedText。您可以尝试用comboBox1.SelectedValue替换它。

此外,必须枚举一个linq变量来使用。

您还可以创建一些变量并检查它们的值在调试时。例如:



: ThePhantomUpvoter's remark is right ; if you get "Enter details" message it means that either textBox1.Text is empty or comboBox1.SelectedText is empty. I would go for comboBox1.SelectedText. You could try to replace it by comboBox1.SelectedValue.
Moreover, a linq variable has to be enumerated to be used.
You could also create some variables and check their values while debugging. For example:

private void button1_Click(object sender, EventArgs e)
{
   string tbText = textBox1.Text;
   string cbValue = (string)comboBox1.SelectedValue;
   if (!string.IsNullOrEmpty(tbText) && !string.IsNullOrEmpty(cbtext)) {
      var res = from result in ds.Results
                where result.REGISTRATION_NUMBER == cbText && result.EXAM_YR == cbValue
                select result;
      List<Result> results = res.ToList();
      if (results != null) {
         resultBindingSource1.DataSource = results;
      }
      else {
         MessageBox.Show("no data found");
      }
   }
   else {
      MessageBox.Show("Enter details");
   }
}


问题不在LINQ代码中,因为这里甚至没有得到评估,如错误所示消息输入详细信息。

似乎文本框或组合中的任何一个都没有设置值。



放置必要的字段验证器以在客户端检测如果有效数据存在,则返回之前。

完成此操作后,您可以使用linq查询来检查正确的过滤。另请参阅其他一些回发事件是否正在重置控件。
The problem is not in LINQ code, as that is not even getting evaluated here, as indicated by the error message "Enter Details".
It seems that either of the textbox or the combo is not have the value being set.

Place required field validators to detect at client side if valid data is present before posting back.
Once this is done, you can work on the linq query to check proper filtering. Also see if some other postback event is resetting the controls.


这篇关于我如何验证来自linq的数据过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆