想用c#做一个简单的登陆,注册界面,请问具体步骤?
下面这张是数据库里面存储的数据,如果匹配成功,点击登陆,弹出弹窗"登陆成功"
如果不成功,弹出"登陆失败"
如果点击注册的话,转到这个页面
填写数据之后点击注册,信息就会被存到数据库里,然后弹出"注册成功"
点重置就把Textbox里面的所有数据清空,重新输入.
我现在写到这一步
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication37
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void B_login_Click(object sender, EventArgs e)
{
if (tb_id.Text == "" || tb_pwd.Text == "")
{
Response.Write("输入登录信息不完整,请重新输入!");
}
SqlConnection con = new SqlConnection("Server = ygu-PC\\SQLEXPRESS;User Id = YGU-PC\\ygu;DataBase = rcloud");
SqlConmmand cmd = new SqlCommand(string.Format("SELECT COUNT(*)FROM rcloud WHERE username = '{0}'AND userpassword = '{1}'", this.tb_id.Text.Trim(), this.tb_pwd.Text.Trim()), con);
}
protected void B_reg_Click(object sender, EventArgs e)
{
Response.Redirect("registe.aspx");
}
}
}
[解决办法]
你最好封装一个简单的数据库访问类,如:
public class DataAccess
{
private OleDbConnection oleDbConnection;
public DataAccess()
{
//
oleDbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=se.mdb;");
if (oleDbConnection.State != ConnectionState.Open)
{
oleDbConnection.Open();
}
}
public int ExecuteSql(string sql)
{
OleDbCommand cmd = new OleDbCommand(sql, oleDbConnection);
return cmd.ExecuteNonQuery();
}
public int ExecuteSql(string sql, ref OleDbParameter[] oleDbParameters)
{
OleDbCommand cmd = new OleDbCommand(sql, oleDbConnection);
cmd.Parameters.AddRange(oleDbParameters);
return cmd.ExecuteNonQuery();
}
这是登录接着你那个写的
if (tb_id.Text == ""
[解决办法]
tb_pwd.Text == "")
{
Response.Write("输入登录信息不完整,请重新输入!");
}
SqlConnection con = new SqlConnection("Server = ygu-PC\\SQLEXPRESS;User Id = YGU-PC\\ygu;DataBase = rcloud");
SqlConmmand cmd = new SqlCommand(string.Format("SELECT COUNT(*)FROM rcloud WHERE username = '{0}'AND userpassword = '{1}'", this.tb_id.Text.Trim(), this.tb_pwd.Text.Trim()), con);
int i = int.Parse(cmd.ExecuteScalar().ToString());
if (i > 0)
Response.Redirect("主页.aspx");
else
{
Response.Write("<script>alert('信息错误,登录失败!')</script>");
}
con.Close();
SqlConnection con = new SqlConnection("Server = ygu-PC\\SQLEXPRESS;User Id = YGU-PC\\ygu;DataBase = rcloud");
if (TextBox1.Text != "" && TextBox2.Text != "" && TextBox3.Text != "" &7 TextBox6.Text != "")
{
string sql=""; //要执行的 sql 语句
SqlConmmand cmd = new SqlCommand(sql, con);//同登录
int i = int.Parse(cmd.ExecuteNonQuery().ToString());
if (i > 0)
{
Response.Write("<script>alert('恭喜您,注册成功!')</script>");
}
}
else
{
Response.Write("<script>alert('用户名或密码不能为空!')</script>");
}