代码拉取完成,页面将自动刷新
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using WindowsFormsApp1.lei;
namespace WindowsFormsApp1
{
public partial class subjectRecord : Form
{
private DBHelper Dbh = new DBHelper();
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
public subjectRecord()
{
InitializeComponent();
}
//查询学生档案信息
public void readStudentMessage(string name)
{
dt.Clear();
string sql;
if(!string.IsNullOrEmpty(name))
{
sql = "select id,姓名,性别,年龄,用户ID from 学生信息 where 姓名 = '{0}'";
sql = string.Format(sql, name);
}else
{
sql = "select id,姓名,性别,年龄,用户ID from 学生信息";
}
dt = Dbh.ExecSqlForDataTable(sql);
this.dataGridView1.DataSource = null;
this.dataGridView1.DataSource = dt;
}
//页面加载展示数据
private void subjectRecord_Load(object sender, EventArgs e)
{
readStudentMessage(null);
}
//根据名字查询数据
private void TeacherQuery_Click(object sender, EventArgs e)
{
readStudentMessage(this.textBoxT1.Text);
}
//添加数据
private void buttonAdd_Click(object sender, EventArgs e)
{
studentAM sdam = new studentAM(null);
if(sdam.ShowDialog() == DialogResult.OK)
{
readStudentMessage(null);
}
}
//修改
private void buttonModiy_Click(object sender, EventArgs e)
{
string name = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
studentAM students = new studentAM(name);
if(students.ShowDialog() == DialogResult.OK)
{
readStudentMessage(null);
}
}
//删除
private void buttonDelete_Click(object sender, EventArgs e)
{
int id = (int)dataGridView1.SelectedRows[0].Cells[0].Value;
string name = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
string sql = "select 姓名 from 学生信息 where 姓名 = '{0}'";
sql = string.Format(sql,name);
dt1 = Dbh.ExecSqlForDataTable(sql);
if(dt1.Rows.Count <= 0)
{
MessageBox.Show("需要删除的信息不存在");
return;
}
else
{
string sql1 = "delete from 学生信息 where id = {0}";
sql1 = string.Format(sql1,id);
int a = Dbh.ExecSql(sql1);
if (a>0)
{
readStudentMessage(null);
MessageBox.Show("删除成功");
return;
}
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。