关于执行查找按钮功能后出现空表的问题。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();
}
}
}