| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 310 人关注过本帖
标题:关于执行查找按钮功能后出现空表的问题。linq to sql
只看楼主 加入收藏
yang54367535
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-12-13
结帖率:100%
收藏
 问题点数:0 回复次数:0 
关于执行查找按钮功能后出现空表的问题。linq to sql
用linq to sql方法  执行查找功能 但是操作后 表内内容是空的..
代码 如下。
请问是哪里出错  我觉得是BindInfo中的问题,怎么改?

using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace t4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string strCon = "Data Source=PC-20120811LXRE\\SQLEXPRESS;Initial Catalog=KCSZ;Persist Security Info=True;User ID=sa;Password=123456789";
        linqtosqlClass linq;
            
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“kCSZDataSet.S”中。您可以根据需要移动或删除它。
           this.sTableAdapter.Fill(this.kCSZDataSet.S);
           // BindInfo();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            BindInfo();
        }
        #region  //查询
        private void BindInfo()
        {
            linq = new linqtosqlClass(strCon);
            if (txtKeyWord.Text == "")
            {
                var result = from info in linq.S
                             select new
                             {
                                 学号 = info.ID,
                                 姓名 = info.Name,
                                 性别 = info.Sex
                             };
                dgvInfo.DataSource = result;
            }
            else
            {
                switch (cboxCondition.Text)
                {
                    case "学号":
                        var resultid = from info in linq.S
                                       where info.ID == txtKeyWord.Text
                                       select new
                                       {
                                           学号 = info.ID,
                                           姓名 = info.Name,
                                           性别 = info.Sex
                                       };
                        dgvInfo.DataSource = resultid;
                        break;

                    case "姓名":
                        var resultname = from info in linq.S
                                         where info.Name.Contains(txtKeyWord.Text)
                                         select new
                                         {
                                             学号 = info.ID,
                                             姓名 = info.Name,
                                             性别 = info.Sex
                                         };
                        dgvInfo.DataSource = resultname;
                        break;

                    case "性别":
                        var resultsex = from info in linq.S
                                        where info.Sex == txtKeyWord.Text
                                        select new
                                        {
                                            学号 = info.ID,
                                            姓名 = info.Name,
                                            性别 = info.Sex
                                        };
                        dgvInfo.DataSource = resultsex;
                        break;


                }
            }
        }
        #endregion

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
搜索更多相关主题的帖子: public 
2012-12-14 22:25
快速回复:关于执行查找按钮功能后出现空表的问题。linq to sql
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039885 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved