level 1
最烦起名字可
楼主
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 ScoreManegement
{
public partial class SearchForm : Form
{
private string sql = "";
private string connStr = @"Data Source = .\sqlexpress;Initial Catalog = 222; Integrated Security = True";
public SearchForm()
{
InitializeComponent();
}
private void SearchForm_Load(object sender, EventArgs e)
{
string _sql = "select XH as'学号',XM as '姓名', ZY as'专业', XB as '性别'," + " CSRQ as '出生日期‘, ZXF as ' 总学分 ',BZ as '备注' from XSB ";
SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter sda = new SqlDataAdapter(_sql, conn);
DataSet ds = new DataSet ( );
sda.Fill(ds);
StuDGV.DataSource = ds.Tables[0].DefaultView;
stuZY.SelectedIndex = 0;
}
private void MakeSqlStr()
{
sql = "";
if (stuXH.Text.Trim()!=string.Empty)
{
sql = "and XH like'%"+stuXH.Text.Trim ()+"%'";
}
if (stuXM.Text.Trim()!=string.Empty)
{
sql = "and XM like'%"+stuXM.Text.Trim()+"%'";
}
if (stuZY .Text!="所有专业")
{
sql+="and ZX='"+ stuZY.Text+"";
}
}
private void search_btn_Click(object sender, EventArgs e)
{
MakeSqlStr();
string _sql = "select XH as'学号',XM as '姓名', ZY as'专业', XB as '性别'," + "CSRQ as '出生日期‘,ZXF as '总学分',BZ as '备注' from XSB where 1=1" + sql;
SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter sda = new SqlDataAdapter(_sql, conn);
DataSet ds = new DataSet ( );
sda.Fill(ds);
StuDGV.DataSource = ds.Tables[0].DefaultView;
}
private void stuXM_TextChanged(object sender, EventArgs e)
{
}
}
}
这是程序
2016年06月28日 11点06分
1
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 ScoreManegement
{
public partial class SearchForm : Form
{
private string sql = "";
private string connStr = @"Data Source = .\sqlexpress;Initial Catalog = 222; Integrated Security = True";
public SearchForm()
{
InitializeComponent();
}
private void SearchForm_Load(object sender, EventArgs e)
{
string _sql = "select XH as'学号',XM as '姓名', ZY as'专业', XB as '性别'," + " CSRQ as '出生日期‘, ZXF as ' 总学分 ',BZ as '备注' from XSB ";
SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter sda = new SqlDataAdapter(_sql, conn);
DataSet ds = new DataSet ( );
sda.Fill(ds);
StuDGV.DataSource = ds.Tables[0].DefaultView;
stuZY.SelectedIndex = 0;
}
private void MakeSqlStr()
{
sql = "";
if (stuXH.Text.Trim()!=string.Empty)
{
sql = "and XH like'%"+stuXH.Text.Trim ()+"%'";
}
if (stuXM.Text.Trim()!=string.Empty)
{
sql = "and XM like'%"+stuXM.Text.Trim()+"%'";
}
if (stuZY .Text!="所有专业")
{
sql+="and ZX='"+ stuZY.Text+"";
}
}
private void search_btn_Click(object sender, EventArgs e)
{
MakeSqlStr();
string _sql = "select XH as'学号',XM as '姓名', ZY as'专业', XB as '性别'," + "CSRQ as '出生日期‘,ZXF as '总学分',BZ as '备注' from XSB where 1=1" + sql;
SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter sda = new SqlDataAdapter(_sql, conn);
DataSet ds = new DataSet ( );
sda.Fill(ds);
StuDGV.DataSource = ds.Tables[0].DefaultView;
}
private void stuXM_TextChanged(object sender, EventArgs e)
{
}
}
}
这是程序