C_Sharp 板


LINE

最近练习登入的部分 主要功能是要 检验有无重复的帐号不过总是会有小问题程式码如下 ------------------------------------------------------------ namespace LOGIN { public partial class FrmLogin : Form { byte[] pic = new byte[2]; bool manager; public FrmLogin() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void button3_Click(object sender, EventArgs e) { if (manager == false) { try { using (SqlConnection conn = new SqlConnection(Settings.Default.ILWCon)) { using (SqlCommand command = new SqlCommand()) { string UserName = textBox1.Text; string Password = FormsAuthentication. HashPasswordForStoringInConfigFile (this.textBox2.Text,"sha1"); if (UserName == "" || Password == "") //===================== { MessageBox.Show("请输入帐号(信箱),及密码"); } else { System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider(); byte[] buf = new byte[15];//用一个阵列来存取使用者输入的密码 rng.GetBytes(buf); //要将在密码编译方面随机位元组填入的阵列。 string salt = Convert.ToBase64String(buf); Password =FormsAuthentication.HashPasswordForStoringInConfigFile(Password + salt, "sha1"); command.CommandText = "Insert into Member(MemEmail, MemPW, Salt) values (@MemEmail, @MemPW, @Salt)"; command.Parameters.Add("@MemEmail",SqlDbType.NVarChar, 50).Value = UserName; command.Parameters.Add("@MemPW",SqlDbType.NVarChar, 80).Value = Password; command.Parameters.Add("@Salt",SqlDbType.NVarChar, 50).Value = salt; 觉得问题出在这里可是不太知道是哪里打错了 conn.Open(); SqlCommand bb = new SqlCommand("Select * FromMember Where Mememail= '" + this.textBox1.Text + "'", conn); SqlDataReader ha = bb.ExecuteReader(); if (ha.Read()) { MessageBox.Show("※请换一个"); this.close(); } else { command.ExecuteNonQuery(); MessageBox.Show("Insert successfully"); } } } } catch (SqlException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { try { using (SqlConnection conn = new SqlConnection(Settings.Default.ILWCon)) { using (SqlCommand command = new SqlCommand()) { string UserName = textBox1.Text; string Password =FormsAuthentication.HashPasswordForStoringIn ConfigFile(this.textBox2.Text,"sha1"); if (UserName == "" || Password == "") //===================== { MessageBox.Show("请输入帐号(信箱),及密码"); } else { System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider(); byte[] buf = new byte[15];//用一个阵列来存取使用者输入的密码 rng.GetBytes(buf); //要将在密码编译方面随机位元组填入的阵列。 string salt = Convert.ToBase64String(buf); //保密方法 Password =FormsAuthentication.HashPasswordForStoringInConfigFile(Password + salt, "sha1"); command.CommandText = "Insert into Manager (EmpAccount, EmpPW,EmpSalt) values (@EmpAccount, @EmpPW, @EmpSalt) command.Connection = conn; command.Parameters.Add("@EmpAccount", SqlDbType.NVarChar, 50).Value = UserName; command.Parameters.Add("@EmpPW",SqlDbType.NVarChar, 50).Value = Password; command.Parameters.Add("@EMPSalt",SqlDbType.NVarChar, 50).Value = salt; conn.Open(); SqlCommand bb = new SqlCommand("Select * FromMember Where Mememail= '" + this.textBox1.Text + "'", conn); SqlDataReader ha = bb.ExecuteReader(); if (ha.Read()) { MessageBox.Show("※请换一个"); } else { command.ExecuteNonQuery(); MessageBox.Show("Insert successfully"); } bb.Dispose(); ha.Dispose(); } } } } catch (SqlException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } --------------------------- 希望各位可以指点一下 感谢 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 125.227.255.79
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1417505473.A.BC2.html
1F:推 Peruheru: 纯粹建议:你应该告诉大家你遇到的"小问题"是什呢情况 12/02 16:17
抱歉 应该要再详细点 F5後 我点选 button3 (注册用) 如果text 不为空值则连线资料库 然後比对 资料库中member表中有无相同资料 如果有则显现 "请换一个" 然後问题在於 我是使用 sqldatareader 他一直显示 ExecuteReader 没有连线 没有connection 不过我一早用using 写完connection 字串了 所以一直卡在这里 是我开连线的位置不对吗 ? ※ 编辑: neo5277 (125.227.255.79), 12/02/2014 17:04:09
2F:推 CrazyAngel: 先试着修正一些问题 1. command没有指定connection 12/02 18:09
3F:→ CrazyAngel: 2. sqldatareader用完要close 12/02 18:10
好的 我去试试看 谢谢你 ※ 编辑: neo5277 (125.227.255.79), 12/02/2014 19:49:30
4F:推 Litfal: 应该先修正那个bb,用使用者输入资料串的SqlCommand... 12/06 12:44







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Soft_Job站内搜寻

TOP