📄 form6.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
/// <summary>
/// Form6 的摘要说明。
/// </summary>
public class Form6 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label 学号;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox sno;
private System.Windows.Forms.TextBox cno;
private System.Windows.Forms.TextBox grade;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private WindowsApplication1.DataSet1 dataSet11;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form6()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.学号 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.sno = new System.Windows.Forms.TextBox();
this.dataSet11 = new WindowsApplication1.DataSet1();
this.cno = new System.Windows.Forms.TextBox();
this.grade = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(0, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(288, 24);
this.label1.TabIndex = 0;
this.label1.Text = "学生成绩插入";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(280, 112);
this.label2.TabIndex = 1;
//
// 学号
//
this.学号.Location = new System.Drawing.Point(8, 72);
this.学号.Name = "学号";
this.学号.Size = new System.Drawing.Size(64, 16);
this.学号.TabIndex = 2;
this.学号.Text = "学号";
this.学号.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 112);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 16);
this.label3.TabIndex = 3;
this.label3.Text = "课程号";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 144);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(64, 16);
this.label4.TabIndex = 4;
this.label4.Text = "成绩";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// sno
//
this.sno.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "stu_infor.学号"));
this.sno.Location = new System.Drawing.Point(96, 72);
this.sno.Name = "sno";
this.sno.Size = new System.Drawing.Size(64, 21);
this.sno.TabIndex = 5;
this.sno.Text = "";
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// cno
//
this.cno.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "stu_infor.课程号"));
this.cno.Location = new System.Drawing.Point(96, 112);
this.cno.Name = "cno";
this.cno.Size = new System.Drawing.Size(64, 21);
this.cno.TabIndex = 6;
this.cno.Text = "";
//
// grade
//
this.grade.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "stu_infor.成绩"));
this.grade.Location = new System.Drawing.Point(96, 144);
this.grade.Name = "grade";
this.grade.Size = new System.Drawing.Size(64, 21);
this.grade.TabIndex = 7;
this.grade.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(216, 80);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 8;
this.button1.Text = "提交";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(216, 120);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 24);
this.button2.TabIndex = 9;
this.button2.Text = "返回";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "stu_infor", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("学号", "学号"),
new System.Data.Common.DataColumnMapping("课程号", "课程号"),
new System.Data.Common.DataColumnMapping("成绩", "成绩")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM stu_infor WHERE (学号 = @Original_学号) AND (课程号 = @Original_课程号) AND (成绩" +
" = @Original_成绩 OR @Original_成绩 IS NULL AND 成绩 IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_学号", System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "学号", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_课程号", System.Data.SqlDbType.VarChar, 3, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "课程号", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_成绩", System.Data.SqlDbType.TinyInt, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "成绩", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=8FB25E96FF90450;packet size=4096;integrated security=SSPI;data sou" +
"rce=8FB25E96FF90450;persist security info=False;initial catalog=celery";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO stu_infor(学号, 课程号, 成绩) VALUES (@学号, @课程号, @成绩); SELECT 学号, 课程号, 成绩 FR" +
"OM stu_infor WHERE (学号 = @学号) AND (课程号 = @课程号)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@学号", System.Data.SqlDbType.VarChar, 6, "学号"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@课程号", System.Data.SqlDbType.VarChar, 3, "课程号"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@成绩", System.Data.SqlDbType.TinyInt, 1, "成绩"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 学号, 课程号, 成绩 FROM stu_infor";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE stu_infor SET 学号 = @学号, 课程号 = @课程号, 成绩 = @成绩 WHERE (学号 = @Original_学号) AND" +
" (课程号 = @Original_课程号) AND (成绩 = @Original_成绩 OR @Original_成绩 IS NULL AND 成绩 IS " +
"NULL); SELECT 学号, 课程号, 成绩 FROM stu_infor WHERE (学号 = @学号) AND (课程号 = @课程号)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@学号", System.Data.SqlDbType.VarChar, 6, "学号"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@课程号", System.Data.SqlDbType.VarChar, 3, "课程号"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@成绩", System.Data.SqlDbType.TinyInt, 1, "成绩"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_学号", System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "学号", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_课程号", System.Data.SqlDbType.VarChar, 3, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "课程号", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_成绩", System.Data.SqlDbType.TinyInt, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "成绩", System.Data.DataRowVersion.Original, null));
//
// Form6
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 181);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.grade);
this.Controls.Add(this.cno);
this.Controls.Add(this.sno);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.学号);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form6";
this.Text = "插入学生成绩";
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
try
{
DataRow add;
add=dataSet11.Tables["stu_infor"].NewRow();
add[0]=sno.Text;
add[1]=cno.Text;
add[2]=Convert.ToInt32(grade.Text);
dataSet11.Tables["stu_infor"].Rows.Add(add);
sqlDataAdapter1.Update(dataSet11,"stu_infor");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -