1.Form1.cs设计
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 比较查询
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“studentDataSet.student”中。您可以根据需要移动或删除它。
this.studentTableAdapter.Fill(this.studentDataSet.student);
//ComboBox comboBox1 = new ComboBox();
comboBox1.Items.Add("大于260");
comboBox1.Items.Add("大于270");
comboBox1.Items.Add("大于280");
comboBox1.Items.Add("大于290");
}
private void button1_Click(object sender, EventArgs e)
{
string str = string.Empty;
switch (comboBox1.SelectedItem.ToString())
{
case "大于260":
str = ">260";
break;
case "大于270":
str = ">270";
break;
case "大于280":
str = ">280";
break;
case "大于290":
str = ">290";
break;
}
SqlConnection con = new SqlConnection("server=localhost\\SQL2005;uid=sa;pwd=1111qq;database=student");
SqlDataAdapter dap = new SqlDataAdapter("select *from student where stuScore"+str,con);
DataSet ds = new DataSet();
dap.Fill(ds,"score");
dataGridView1.DataSource = ds.Tables["score"].DefaultView;
//dataGridView1.DataBind();
}
}
}