第六章 数据筛选和排序
来源:互联网 发布:知乎 重金求子 编辑:程序博客网 时间:2024/05/15 08:25
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace WindowsFormsApplication1{ public partial class Form2 : Form { DBHelper db = new DBHelper(); DataSet ds = new DataSet(); SqlDataAdapter der = null; public Form2() { InitializeComponent(); } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } public void getstudent() { //清空原有数据 if (ds.Tables["student"] != null) { ds.Tables["student"].Clear(); } string ent =@"SELECT [StudentNo] as 学号 ,[LoginPwd] as 密码 ,[StudentName] as 姓名 ,[Sex] ,[GradeId] ,[Phone] as 电话 ,[Address] as 地址 ,[BornDate] as 出生日期 ,[Email] FROM [MySchool].[dbo].[Student] "; der = new SqlDataAdapter(ent,db.Connection); der.Fill(ds,"student"); this.dataGridView1.DataSource=ds.Tables["student"]; } private void Form2_Load(object sender, EventArgs e) { getstudent(); } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { // string message = string.Format("选中了{0}节点,深度是{1}",treeView1.SelectedNode.Text,treeView1.SelectedNode.Level); // MessageBox.Show(message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information); shitu(); } public void shitu() { DataView dv = new DataView(ds.Tables["student"]); string filer = ""; if(treeView1.SelectedNode.Text.Equals("S1")){ filer = "[GradeId]=1"; }else if(treeView1.SelectedNode.Text.Equals("S2")) { filer = "[GradeId]=2"; }else if(treeView1.SelectedNode.Text.Equals("Y2")) { filer="[GradeId]=3"; } if(treeView1.SelectedNode.Level==2){ MessageBox.Show(treeView1.SelectedNode.Level.ToString()); string gender = treeView1.SelectedNode.Tag.ToString(); int num = Convert.ToInt32(treeView1.SelectedNode.Parent.Tag); MessageBox.Show(gender); filer = "GradeId="+num+" and Sex='"+gender+"'"; } dv.RowFilter = filer; dv.Sort = "GradeId desc"; this.dataGridView1.DataSource = dv; } private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult fell; fell = MessageBox.Show("确定要删除该学生吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); MessageBox.Show(fell.ToString()); if (fell == DialogResult.Yes) { if (dataGridView1.SelectedRows.Count > 0) { string studentNo = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); MessageBox.Show(studentNo); try { db.OpenConnection(); string sql = string.Format("delete from dbo.Student where StudentNo='{0}'", studentNo); SqlCommand command = new SqlCommand(sql, db.Connection); int result = command.ExecuteNonQuery(); MessageBox.Show(result.ToString()); if (result == 1) { MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); getstudent(); } } catch (Exception r) { MessageBox.Show(r.Message); MessageBox.Show("系统出现错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { db.CloseConnection(); } } } } private void 获得idToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show(this.dataGridView1.SelectedCells[0].Value.ToString()); } } }
0 0
- 第六章 数据筛选和排序
- map 数据筛选和排序
- 使用 DataView 对数据排序和筛选
- 数据集的筛选和排序
- 脱机数据的排序、搜索和筛选
- 黑马程序员--数据筛选和排序
- 排序和筛选数据 (ADO.NET)
- pandas筛选排序数据
- xsl中对xml数据的排序和筛选
- C#操作数据库(动态筛选和排序数据库数据)
- C#学习笔记(十二)-数据筛选和排序
- PourOver – 快速筛选和排序大的数据集合
- 使用Pandas对数据进行筛选和排序
- 带有本地数据排序和筛选的RecyclerView Adapter
- 使用Pandas对数据进行筛选和排序
- 【Python学习系列二十二】pandas数据筛选和排序
- 使用Pandas对数据进行筛选和排序
- 使用Pandas对数据进行筛选和排序
- opencv3.1 surf特征匹配
- labview生成安装包后,无法正常打印报表问题
- zookeeper介绍(二)
- 2048网页小游戏
- 行为驱动开发在 Python 开发测试中的应用
- 第六章 数据筛选和排序
- py打包成exe
- 第十五周-判断字符串是否为回文
- NSSet、NSArray的日期排序
- 解决虚拟机打开不了?提示VMware Workstation cannot connect to the virtual machine的问题
- 用VS2012导入工程时出现error MSB8020错误
- linux 和 vim 学习笔记
- 解决Android 错误 couldn't find "xxx.so" is 32-bit instead of 64-bit
- 关于burpsuite无法抓取https包问题的解决