版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、数据库实验四 一 实验内容1. 利用DataGridView显示数据1) 显示数据库中对应表的所有数据2) 根据条件查询2. 利用新建的WinForm界面新增、编辑数据实现删除当前选中的某一行。二 实验代码 <?xml version="1.0" encoding="utf-8" ?><configuration> <appSettings> <add key="ConnectionString" value="Integrated Security=sspi;server=loca
2、lhost;database=db_stu;uid=sa;pwd=123"/> </appSettings></configuration>StudenntEditForm.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Stude
3、ntManage public partial class StudentEditForm : Form public StudentEditForm() InitializeComponent(); public string StudentID; public string Optype; private void buttonSubmit_Click(object sender, EventArgs e) string sql = string.Empty; try if (Optype.Equals("ADD") sql = "INSERT INTO St
4、udent(no,sid,name,grade,email,qq,telephone) VALUES(" sql += "'" + Guid.NewGuid() + "'," if (string.IsNullOrEmpty(this.textBoxSno.Text.ToString() MessageBox.Show("学号不能为空"); return; else sql += "'" + this.textBoxSno.Text.ToString() + "'
5、," if (string.IsNullOrEmpty(this.textBoxName.Text.ToString() MessageBox.Show("姓名不能为空"); return; else sql += "'" + this.textBoxName.Text.ToString() + "'," sql += "'" + boBoxGrade.SelectedItem.ToString() + "'," if (!string.IsNullOr
6、Empty(this.textBoxEmail.Text.ToString() sql += "'" + this.textBoxEmail.Text.ToString() + "'," else sql += "''," if (!string.IsNullOrEmpty(this.textBoxQQ.Text.ToString() sql += "'" + this.textBoxQQ.Text.ToString() + "'," else s
7、ql += "''," if (!string.IsNullOrEmpty(this.textBoxTelephone.Text.ToString() sql += "'" + this.textBoxTelephone.Text.ToString() + "'," else sql += "''," sql = sql.Substring(0, sql.Length - 1); sql += ")" DBUtility.DbHelperSQL.E
8、xecuteSql(sql); else sql = "UPDATE Student SET " sql += "sid='" + this.textBoxSno.Text.ToString() + "'," sql += "name='" + this.textBoxName.Text.ToString() + "'," sql += "grade='" + boBoxGrade.SelectedItem.ToString() + &
9、quot;'," sql += "email='" + this.textBoxEmail.Text.ToString() + "'," sql += "qq='" + this.textBoxQQ.Text.ToString() + "'," sql += "telephone='" + this.textBoxTelephone.Text.ToString() + "'" sql += " WHE
10、RE ID='" + StudentID + "'" DBUtility.DbHelperSQL.ExecuteSql(sql); catch (Exception ex) MessageBox.Show(ex.Message); return; this.Close(); private void StudentEditForm_Load(object sender, EventArgs e) boBoxGrade.SelectedItem = "2010级?"/默认当前下拉框选项 if (Optype.Equals(&quo
11、t;EDIT") GetStudentInfo(StudentID); private void GetStudentInfo(string StudentID) string sql = "SELECT ID,sid,name,grade,email,qq,telephone FROM Student " + " WHERE ID='" + StudentID + "'" DataSet dataSet = DBUtility.DbHelperSQL.Query(sql); if (dataSet != n
12、ull && dataSet.Tables0.Rows.Count > 0) this.textBoxSno.Text = dataSet.Tables0.Rows0"SNO".ToString(); this.textBoxName.Text = dataSet.Tables0.Rows0"Name".ToString(); boBoxGrade.SelectedItem = dataSet.Tables0.Rows0"Grade" this.textBoxEmail.Text = dataSet.Tables
13、0.Rows0"Email".ToString(); this.textBoxQQ.Text = dataSet.Tables0.Rows0"QQ".ToString(); this.textBoxTelephone.Text = dataSet.Tables0.Rows0"Telephone".ToString(); StudentForm.Designer.csnamespace StudentManage partial class StudentForm / <summary> / Required designe
14、r variable. / </summary> private System.ComponentModel.IContainer components = null; / <summary> / Clean up any resources being used. / </summary> / <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected overr
15、ide void Dispose(bool disposing) if (disposing && (components != null) components.Dispose(); base.Dispose(disposing); #region Windows Form Designer generated code / <summary> / Required method for Designer support - do not modify / the contents of this method with the code editor. / &l
16、t;/summary> private void InitializeComponent() this.lblSeach = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); this.btnSearch = new System.Windows.Forms.Button(); this.txtName = new System.Windows.Forms.TextBox(); this.txtNo = new System.Windows.Forms.TextBox();
17、this.lblName = new System.Windows.Forms.Label(); this.lblNo = new System.Windows.Forms.Label(); this.panel2 = new System.Windows.Forms.Panel(); this.gridStudent = new System.Windows.Forms.DataGridView(); this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.SNO = new System.Windows.Fo
18、rms.DataGridViewTextBoxColumn(); this.SName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Grade = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.EMail = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.QQ = new System.Windows.Forms.DataGridViewTextBoxColumn(); th
19、is.Telephone = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.label1 = new System.Windows.Forms.Label(); this.btnAdd = new System.Windows.Forms.Button(); this.btnDelete = new System.Windows.Forms.Button(); this.btnEdit = new System.Windows.Forms.Button(); this.panel1.SuspendLayout(); thi
20、s.panel2.SuspendLayout(); (System.ComponentModel.ISupportInitialize)(this.gridStudent).BeginInit(); this.SuspendLayout(); / / lblSeach / this.lblSeach.AutoSize = true; this.lblSeach.Location = new System.Drawing.Point(18, 38); this.lblSeach.Name = "lblSeach" this.lblSeach.Size = new System
21、.Drawing.Size(29, 12); this.lblSeach.TabIndex = 0; this.lblSeach.Text = "检索" / / panel1 / this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel1.Controls.Add(this.btnSearch); this.panel1.Controls.Add(this.txtName); this.panel1.Controls.Add(this.txtNo); this.pan
22、el1.Controls.Add(this.lblName); this.panel1.Controls.Add(this.lblNo); this.panel1.Location = new System.Drawing.Point(14, 45); this.panel1.Name = "panel1" this.panel1.Size = new System.Drawing.Size(655, 40); this.panel1.TabIndex = 1; / / btnSearch / this.btnSearch.Location = new System.Dra
23、wing.Point(490, 6); this.btnSearch.Name = "btnSearch" this.btnSearch.Size = new System.Drawing.Size(75, 23); this.btnSearch.TabIndex = 3; this.btnSearch.Text = "查询" this.btnSearch.UseVisualStyleBackColor = true; this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click
24、); / / txtName / this.txtName.Location = new System.Drawing.Point(327, 9); this.txtName.Name = "txtName" this.txtName.Size = new System.Drawing.Size(124, 21); this.txtName.TabIndex = 2; / / txtNo / this.txtNo.Location = new System.Drawing.Point(133, 9); this.txtNo.Name = "txtNo"
25、this.txtNo.Size = new System.Drawing.Size(124, 21); this.txtNo.TabIndex = 1; this.txtNo.TextChanged += new System.EventHandler(this.txtNo_TextChanged); / / lblName / this.lblName.AutoSize = true; this.lblName.Location = new System.Drawing.Point(280, 16); this.lblName.Name = "lblName" this.
26、lblName.Size = new System.Drawing.Size(41, 12); this.lblName.TabIndex = 0; this.lblName.Text = "姓名" / / lblNo / this.lblNo.AutoSize = true; this.lblNo.Location = new System.Drawing.Point(86, 16); this.lblNo.Name = "lblNo" this.lblNo.Size = new System.Drawing.Size(41, 12); this.lb
27、lNo.TabIndex = 0; this.lblNo.Text = "学号" / / panel2 / this.panel2.BackColor = System.Drawing.SystemColors.Control; this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel2.Controls.Add(this.gridStudent); this.panel2.Location = new System.Drawing.Point(14, 101); t
28、his.panel2.Name = "panel2" this.panel2.Size = new System.Drawing.Size(655, 302); this.panel2.TabIndex = 2; / / gridStudent / this.gridStudent.AllowUserToAddRows = false; this.gridStudent.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; th
29、is.gridStudent.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn this.ID, this.SNO, this.SName, this.Grade, this.EMail, this.QQ, this.Telephone); this.gridStudent.Location = new System.Drawing.Point(3, 7); this.gridStudent.Name = "gridStudent" this.gridStudent.ReadOnly = true; t
30、his.gridStudent.RowTemplate.Height = 23; this.gridStudent.Size = new System.Drawing.Size(646, 290); this.gridStudent.TabIndex = 0; this.gridStudent.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.gridStudent_CellClick); / / ID / this.ID.DataPropertyName = "ID" this.
31、ID.HeaderText = "ID" this.ID.Name = "ID" this.ID.ReadOnly = true; this.ID.Visible = false; / / SNO / this.SNO.DataPropertyName = "sid" this.SNO.HeaderText = "学号" this.SNO.Name = "sid" this.SNO.ReadOnly = true; / / SName / this.SName.DataPropertyName
32、= "name" this.SName.HeaderText = "姓名" this.SName.Name = "name" this.SName.ReadOnly = true; / / Grade / this.Grade.DataPropertyName = "grade" this.Grade.HeaderText = "年级" this.Grade.Name = "grade" this.Grade.ReadOnly = true; / / EMail / this
33、.EMail.DataPropertyName = "email" this.EMail.HeaderText = "E-mail" this.EMail.Name = "eMail" this.EMail.ReadOnly = true; / / QQ / this.QQ.DataPropertyName = "qq" this.QQ.HeaderText = "QQ" this.QQ.Name = "qq" this.QQ.ReadOnly = true; / / Tel
34、ephone / this.Telephone.DataPropertyName = "telephone" this.Telephone.HeaderText = "电话" this.Telephone.Name = "telephone" this.Telephone.ReadOnly = true; / / label1 / this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(18, 94); this.label1.Name
35、= "label1" this.label1.Size = new System.Drawing.Size(29, 12); this.label1.TabIndex = 0; this.label1.Text = "列表" / / btnAdd / this.btnAdd.Location = new System.Drawing.Point(183, 425); this.btnAdd.Name = "btnAdd" this.btnAdd.Size = new System.Drawing.Size(75, 23); this.
36、btnAdd.TabIndex = 3; this.btnAdd.Text = "新增" this.btnAdd.UseVisualStyleBackColor = true; this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); / / btnDelete / this.btnDelete.Location = new System.Drawing.Point(422, 425); this.btnDelete.Name = "btnDelete" this.btnDelete
37、.Size = new System.Drawing.Size(75, 23); this.btnDelete.TabIndex = 3; this.btnDelete.Text = "删除" this.btnDelete.UseVisualStyleBackColor = true; this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click); / / btnEdit / this.btnEdit.Location = new System.Drawing.Point(297, 425); t
38、his.btnEdit.Name = "btnEdit" this.btnEdit.Size = new System.Drawing.Size(75, 23); this.btnEdit.TabIndex = 3; this.btnEdit.Text = "编辑" this.btnEdit.UseVisualStyleBackColor = true; this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click); / / StudentForm / this.AutoScaleDi
39、mensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(681, 469); this.Controls.Add(this.btnDelete); this.Controls.Add(this.btnEdit); this.Controls.Add(this.btnAdd); this.Controls.Add(this.label1); this.Co
40、ntrols.Add(this.lblSeach); this.Controls.Add(this.panel2); this.Controls.Add(this.panel1); this.Name = "StudentForm" this.Text = "数据库实验" this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.panel2.ResumeLayout(false); (System.ComponentModel.ISupportInitialize)(this.
41、gridStudent).EndInit(); this.ResumeLayout(false); this.PerformLayout(); #endregion private System.Windows.Forms.Label lblSeach; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label lblNo; private System.Windows.Forms.Button btnSearch; private System.Windows.Forms.TextBox txt
42、Name; private System.Windows.Forms.TextBox txtNo; private System.Windows.Forms.Label lblName; private System.Windows.Forms.Panel panel2; private System.Windows.Forms.DataGridView gridStudent; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button btnAdd; private System.Window
43、s.Forms.Button btnDelete; private System.Windows.Forms.Button btnEdit; private System.Windows.Forms.DataGridViewTextBoxColumn ID; private System.Windows.Forms.DataGridViewTextBoxColumn SNO; private System.Windows.Forms.DataGridViewTextBoxColumn SName; private System.Windows.Forms.DataGridViewTextBox
44、Column Grade; private System.Windows.Forms.DataGridViewTextBoxColumn EMail; private System.Windows.Forms.DataGridViewTextBoxColumn QQ; private System.Windows.Forms.DataGridViewTextBoxColumn Telephone; studentForm.csusing 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 DBUtility;namespace StudentManage public partial class StudentForm
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中国计量大学现代科技学院《商务英语(上)》2023-2024学年第一学期期末试卷
- 塔设计的课程设计
- 2024年店铺装修合同范本
- 2024年版商务考察团组织合同3篇
- 中国地质大学(武汉)《人工智能导论》2021-2022学年第一学期期末试卷
- 岩土数值模拟课程设计
- 2024年家电连锁加盟合同
- 2024企业合同电子化与数据安全保护系统采购合同3篇
- 2024年度股权转让合同:关于A公司0%股权转让给B公司的详细约定3篇
- 2024年度桥西区图书馆临时展览馆租赁协议3篇
- 生物脊椎动物(鱼)课件-2024-2025学年人教版生物七年级上册
- 浙江省杭州市拱墅区2023-2024学年六年级(上)期末数学试卷
- 2024年物业化粪池维护合同3篇
- 2024年度互联网医院建设与运营合同3篇
- 无创呼吸机护理
- 趸船相关项目实施方案
- 苏州市苏科版二年级下册劳动与技术全一册全部教案(定稿)
- 《Python程序设计》课件-1:开发环境搭建
- 第7课《谁是最可爱的人》课件-2023-2024学年统编版语文七年级下册
- 健康体检专家共识
- 浙江省杭州市2024-2025学年高三上学期期中教学质量检测政治试题 含答案
评论
0/150
提交评论