回复 7楼 Versetk
现在又遇到了新的问题.执行查找 操作后在表中显示的是空的表。。请问是哪里错了
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();
}
}
}