当前位置:
首页 > 编程开发 > Objective-C编程 >
-
C#运行SQL语句实例2
实战练习二:“密码修改”模块示例代码:
“密码修改”窗体详细设置(在InitializeComponent();处击右键,选择“转到定义”获取的代码):
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txt_OldPwd = new System.Windows.Forms.TextBox();
this.txt_NewPwd = new System.Windows.Forms.TextBox();
this.txt_ConfirmPwd = new System.Windows.Forms.TextBox();
this.btn_OK = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(17, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 12);
this.label1.TabIndex = 0;
this.label1.Text = "旧密码:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(17, 51);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(53, 12);
this.label2.TabIndex = 1;
this.label2.Text = "新密码:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(17, 87);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(65, 12);
this.label3.TabIndex = 2;
this.label3.Text = "密码确认:";
//
// txt_OldPwd
//
this.txt_OldPwd.Location = new System.Drawing.Point(99, 12);
this.txt_OldPwd.Name = "txt_OldPwd";
this.txt_OldPwd.PasswordChar = '*';
this.txt_OldPwd.Size = new System.Drawing.Size(100, 21);
this.txt_OldPwd.TabIndex = 3;
//
// txt_NewPwd
//
this.txt_NewPwd.Location = new System.Drawing.Point(99, 48);
this.txt_NewPwd.Name = "txt_NewPwd";
this.txt_NewPwd.PasswordChar = '*';
this.txt_NewPwd.Size = new System.Drawing.Size(100, 21);
this.txt_NewPwd.TabIndex = 4;
//
// txt_ConfirmPwd
//
this.txt_ConfirmPwd.Location = new System.Drawing.Point(99, 84);
this.txt_ConfirmPwd.Name = "txt_ConfirmPwd";
this.txt_ConfirmPwd.PasswordChar = '*';
this.txt_ConfirmPwd.Size = new System.Drawing.Size(100, 21);
this.txt_ConfirmPwd.TabIndex = 5;
//
// btn_OK
//
this.btn_OK.Location = new System.Drawing.Point(124, 121);
this.btn_OK.Name = "btn_OK";
this.btn_OK.Size = new System.Drawing.Size(75, 23);
this.btn_OK.TabIndex = 6;
this.btn_OK.Text = "确定";
this.btn_OK.UseVisualStyleBackColor = true;
this.btn_OK.Click += new System.EventHandler(this.btn_OK_Click);
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(222, 153);
this.Controls.Add(this.btn_OK);
this.Controls.Add(this.txt_ConfirmPwd);
this.Controls.Add(this.txt_NewPwd);
this.Controls.Add(this.txt_OldPwd);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "密码修改";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
“确定”按钮源码:
private void btn_OK_Click(object sender, EventArgs e)
{
if (txt_OldPwd.Text == "")
{
MessageBox.Show("请输入旧密码","系统提示");
txt_OldPwd.Focus();
}
else if (txt_NewPwd.Text == "")
{
MessageBox.Show("请输入新密码", "系统提示");
txt_NewPwd.Focus();
}
else if (txt_ConfirmPwd.Text == "")
{
MessageBox.Show("请输入确认密码", "系统提示");
txt_ConfirmPwd.Focus();
}
else if (txt_ConfirmPwd.Text != txt_NewPwd.Text)
{
MessageBox.Show("确认密码必须和新密码相同!", "系统提示");
txt_ConfirmPwd.Focus();
}
else
{
//定义连接字符串
string strConnection = "Server=168.10.10.86;initial catalog=Tele_Sale;user id=sa;password=sd;Connect Timeout=30";
//用连接字符串创建一个数据库连接对象
SqlConnection objConnection = new SqlConnection(strConnection);
//使用数据库连接对象连接数据库
objConnection.Open();
//先判断旧密码是否正确
SqlCommand SqlCmd_Select = new SqlCommand("select PassWord from MissInfo where MissID='"+MissID+"'", objConnection);
string TempPass = SqlCmd_Select.ExecuteScalar().ToString();
// MessageBox.Show(TempPass, "");
if (TempPass != txt_OldPwd.Text)
{
MessageBox.Show("对不起,您输入的旧密码不正确!", "系统提示");
txt_OldPwd.Focus();
}
else
{
//基于数据库连接对象创建一个sql命令
SqlCommand SqlCmd = new SqlCommand("update MissInfo set MissName='技术主管' where MissID='234'", objConnection);
//执行不返回结果的sql命令
SqlCmd.ExecuteNonQuery();
MessageBox.Show("密码修改成功!", "系统提示");
}
//关闭数据库连接
objConnection.Close();
}
}
“密码修改”窗体详细设置(在InitializeComponent();处击右键,选择“转到定义”获取的代码):
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txt_OldPwd = new System.Windows.Forms.TextBox();
this.txt_NewPwd = new System.Windows.Forms.TextBox();
this.txt_ConfirmPwd = new System.Windows.Forms.TextBox();
this.btn_OK = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(17, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 12);
this.label1.TabIndex = 0;
this.label1.Text = "旧密码:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(17, 51);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(53, 12);
this.label2.TabIndex = 1;
this.label2.Text = "新密码:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(17, 87);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(65, 12);
this.label3.TabIndex = 2;
this.label3.Text = "密码确认:";
//
// txt_OldPwd
//
this.txt_OldPwd.Location = new System.Drawing.Point(99, 12);
this.txt_OldPwd.Name = "txt_OldPwd";
this.txt_OldPwd.PasswordChar = '*';
this.txt_OldPwd.Size = new System.Drawing.Size(100, 21);
this.txt_OldPwd.TabIndex = 3;
//
// txt_NewPwd
//
this.txt_NewPwd.Location = new System.Drawing.Point(99, 48);
this.txt_NewPwd.Name = "txt_NewPwd";
this.txt_NewPwd.PasswordChar = '*';
this.txt_NewPwd.Size = new System.Drawing.Size(100, 21);
this.txt_NewPwd.TabIndex = 4;
//
// txt_ConfirmPwd
//
this.txt_ConfirmPwd.Location = new System.Drawing.Point(99, 84);
this.txt_ConfirmPwd.Name = "txt_ConfirmPwd";
this.txt_ConfirmPwd.PasswordChar = '*';
this.txt_ConfirmPwd.Size = new System.Drawing.Size(100, 21);
this.txt_ConfirmPwd.TabIndex = 5;
//
// btn_OK
//
this.btn_OK.Location = new System.Drawing.Point(124, 121);
this.btn_OK.Name = "btn_OK";
this.btn_OK.Size = new System.Drawing.Size(75, 23);
this.btn_OK.TabIndex = 6;
this.btn_OK.Text = "确定";
this.btn_OK.UseVisualStyleBackColor = true;
this.btn_OK.Click += new System.EventHandler(this.btn_OK_Click);
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(222, 153);
this.Controls.Add(this.btn_OK);
this.Controls.Add(this.txt_ConfirmPwd);
this.Controls.Add(this.txt_NewPwd);
this.Controls.Add(this.txt_OldPwd);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "密码修改";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
“确定”按钮源码:
private void btn_OK_Click(object sender, EventArgs e)
{
if (txt_OldPwd.Text == "")
{
MessageBox.Show("请输入旧密码","系统提示");
txt_OldPwd.Focus();
}
else if (txt_NewPwd.Text == "")
{
MessageBox.Show("请输入新密码", "系统提示");
txt_NewPwd.Focus();
}
else if (txt_ConfirmPwd.Text == "")
{
MessageBox.Show("请输入确认密码", "系统提示");
txt_ConfirmPwd.Focus();
}
else if (txt_ConfirmPwd.Text != txt_NewPwd.Text)
{
MessageBox.Show("确认密码必须和新密码相同!", "系统提示");
txt_ConfirmPwd.Focus();
}
else
{
//定义连接字符串
string strConnection = "Server=168.10.10.86;initial catalog=Tele_Sale;user id=sa;password=sd;Connect Timeout=30";
//用连接字符串创建一个数据库连接对象
SqlConnection objConnection = new SqlConnection(strConnection);
//使用数据库连接对象连接数据库
objConnection.Open();
//先判断旧密码是否正确
SqlCommand SqlCmd_Select = new SqlCommand("select PassWord from MissInfo where MissID='"+MissID+"'", objConnection);
string TempPass = SqlCmd_Select.ExecuteScalar().ToString();
// MessageBox.Show(TempPass, "");
if (TempPass != txt_OldPwd.Text)
{
MessageBox.Show("对不起,您输入的旧密码不正确!", "系统提示");
txt_OldPwd.Focus();
}
else
{
//基于数据库连接对象创建一个sql命令
SqlCommand SqlCmd = new SqlCommand("update MissInfo set MissName='技术主管' where MissID='234'", objConnection);
//执行不返回结果的sql命令
SqlCmd.ExecuteNonQuery();
MessageBox.Show("密码修改成功!", "系统提示");
}
//关闭数据库连接
objConnection.Close();
}
}
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
JavaScript判断两个数组相等的四类方法
js如何操作video标签
React实战--利用甘特图和看板,强化Paas平
【记录】正则替换的偏方
前端下载 Blob 类型整理
抽象语法树AST必知必会
关于JS定时器的整理
JS中使用Promise.all控制所有的异步请求都完
js中字符串的方法
import-local执行流程与node模块路径解析流程