共 1 篇文章

标签:c注册用户窗口,如何将注册信息如账号密码写入数据库? (c 数据集操作数据库)

c注册用户窗口,如何将注册信息如账号密码写入数据库? (c 数据集操作数据库)

protected void Button1_Click(object sender, EventArgs e) { if (Check(TextBox1.Text) || Check(TextBox2.Text) || Check(TextBox3.Text) || Check(TextBox4.Text) ) //判断 { Label8.Text = “用户信息中不辩历团能够包含特殊字符如,’,//,\\等,请审核”; //输出信息 } else { else { try { SqlConnection con = new SqlConnection(“server='(local)’;database=’Register’;uid=’sa’;pwd=’sa’”); //建立连接 con.Open(); //打开连接 string strsql = “insert into register (username,password,QQ,Email) values (‘” + TextBox1.Text + “‘,’” + TextBox2.Text + “‘,’” + TextBox3.Text + “‘,’” + TextBox4.Text + “‘,0)”; SqlCommand cmd = new SqlCommand(strsql,con); //创建执行 cmd.ExecuteNonQuery(); //执行SQL Label8.Text = “注册成功,请牢记您的信息”; //提示成功 } catch { Label8.Text = “出现错误信息,请返回给管理员”; //抛出异常 } } } protected bool Check(string text) //判断实现 { if (text.Contains(“”) || text.Contains(“‘”) || text.Contains(“//”) || text.Contains(“\\”)) //检查字串 { return true; //返回真 } else { return false; //返回假 } } 检测注册名重复的代码: string check = “select * from register where...

技术分享