C# Learn About 数据库注册
来源:互联网 发布:淘宝图片显示不全 编辑:程序博客网 时间:2024/05/18 03:48
数据库注册,这个在我们的生活中使用的非常多,有些是有固定的模式的。
=>1.贴代码如下:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace LoginTest2{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } /* * 获得输入参数,通过拼接成SQL语句,提交给ADO.NET 去执行 */ /// <summary> /// 这是一个使用ADO.NET注册用户名和密码到数据库的练习 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnReg_Click(object sender, EventArgs e) { string uid = txtUid.Text.Trim(); string pwd = txtPwd.Text.Trim(); string pwd2 = txtPwd2.Text.Trim(); if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(pwd) || string.IsNullOrEmpty(pwd2)) { MessageBox.Show("请填写完整的信息"); return ; } if (pwd != pwd2) { MessageBox.Show("两次密码输入不一致"); return; } else { string connStr = @"server=.;database=MyDB;uid=sa;pwd=123;integrated security=true"; // string sql = "insert into Table_loginTest(uid,pwd)values('"+uid+"','"+pwd+"')"; string sql= string.Format("insert into Table_loginTest(uid,pwd)values('{0}','{1}')", uid,pwd); using (SqlConnection conn = new SqlConnection(connStr)) { using(SqlCommand cmd=new SqlCommand(sql,conn)) { conn.Open(); int count = cmd.ExecuteNonQuery(); MessageBox.Show(count > 0 ? "注册成功" : "注册失败"); } } } } }}
=>必要的说明:
关键词语:
1.如何判断字符串输入是否为空
if (string.IsNullOrEmpty(uid) ||string.IsNullOrEmpty(pwd) ||string.IsNullOrEmpty(pwd2))
2.数据库的集成安全验证
string connStr = @"server=.;database=MyDB;uid=sa;pwd=123;integrated security=true";
3.格式化字符串的应用(通过这种方式在一串字符串中,修改某个字符串对应的值)
string sql= string.Format("insert into Table_loginTest(uid,pwd)values('{0}','{1}')", uid,pwd);
4.标准的注释写法
/*
* 获得输入参数,通过拼接成SQL语句,提交给ADO.NET 去执行
*/
!注意 此处写函数整个的概括,以及算法过程
-----------------------------------------------------------------
/// <summary>
/// 这是一个使用ADO.NET注册用户名和密码到数据库的练习
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
!注意 此处书写该函数的一些调用标识语句
-----------------------------------------------------------------
5.如何判断注册成功
int count = cmd.ExecuteNonQuery();
=>疑问
1.如何防止重复注册
---write at 2016-1-1 待续
- C# Learn About 数据库注册
- Effective C#之Item 48:Learn About Tools and Resources
- Effective C#之Item 50:Learn About the ECMA Standard
- learn about loader
- Learn about SAPUI5
- c# 注册窗体 连接数据库
- Learn the truth about Bush
- Learn more about Web driver
- c#简单的注册程序,连接数据库
- Start to learn something about "Atlas"
- Please, please, please, learn about injection attacks!
- From Learn About the Ext JavaScript Library
- C++ For Beginners - Learn about C++
- Learn about HDFS File System Shell
- Learn about Markdown with CSDN markdown editor
- c# datagridview‘s learn
- About TreeView of C#
- What did I learn from the QucikStart about DAAB?
- android中三种onClick事件的实现,与对比
- 利用HTML制作一二级导航菜单
- MyBatis,动态传入表名,字段名的解决办法
- LSGO软件技术团队2015~2016学年第十二周(1116~1122)总结
- poi使用HSSFWorkbook 导出excel
- C# Learn About 数据库注册
- 第9章 客户端检测小结
- WebView 使用总结
- 2016-01-01 FFC
- LSGO软件技术团队2015~2016学年第十三周(1123~1129)总结
- 韩信点兵
- Android按钮单击事件的四种常用写法总结
- 类与对象
- java.util.Map的衍生