真心菜鸟写了点击登录的代码。但是怎么验证呢。。验证成功后跳转的代码又该怎么写呢
就是点击登录按钮后的跳转。。。protected void submit_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("server=localhost;database=jtgl;user=sa;password=sa");
SqlCommand cmd = new SqlCommand("select * from ajdjb,where user="admin",psd="admin"",cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
--------------------编程问答--------------------
先把书看看呀 汗 --------------------编程问答-------------------- /// <summary>
/// 登录
/// </summary>
/// <param name="sql">SQL</param>
/// <param name="id">学号</param>
/// <param name="pwd">密码</param>
/// <returns>是否合法</returns>
public static bool login(String sql, String id, String pwd)
{
OracleConnection con = new OracleConnection(ConfigurationManager.AppSettings["ConnStrOrcl"]);
//SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ToString ());
con.Open();
OracleCommand com = new OracleCommand(sql, con);
com.Parameters.Add(new OracleParameter(":id", OracleType.VarChar,20));
com.Parameters[":id"].Value = id;
com.Parameters.Add(new OracleParameter(":pwd", OracleType.VarChar, 20));
com.Parameters[":pwd"].Value = pwd;
int isEx = Convert.ToInt32(com.ExecuteScalar());
if (isEx > 0)
{
con.Close();
return true;
}
else
{
con.Close();
return false;
}
}
if(login("..."))
{
//跳转
} --------------------编程问答-------------------- 求临时性指导。。。 --------------------编程问答-------------------- 查询数据后,最好返回实体··· if(obj!=null){ 用户成功登陆 } else{ 用户名或密码错误 } --------------------编程问答-------------------- if(ds!=null){
response.redirect("main.aspx")
} --------------------编程问答-------------------- protected void submit_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("server=localhost;database=jtgl;user=sa;password=sa");
SqlCommand cmd = new SqlCommand("select * from ajdjb,where user="admin",psd="admin"",cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);//查询的数据
DataSet ds=new DataSet(); //结果集
//把数据放到结果集中去
da.Fill(ds);
//判读是否有数据
if (ds.Tables[0].Rows.Count == 0)
{
Response.Write("没有该数据");
}
else {
Response.Write("登陆成功");
}
} --------------------编程问答-------------------- --------------------编程问答-------------------- 登录成功: Response.Redirect(FormsAuthentication.DefaultUrl);
webconfig配置
<authentication mode="Forms">
<forms loginUrl="Login.aspx" timeout="2880" defaultUrl="~\WebManager\index.html" />
</authentication> --------------------编程问答-------------------- 可使用jquery来进行验证,有关跳转的有非常多的解决方式。 --------------------编程问答-------------------- Response.Redirect("url") --------------------编程问答--------------------
protected void submit_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("server=localhost;database=jtgl;user=sa;password=sa");
SqlCommand cmd = new SqlCommand("select count(id) from ajdjb,where user="admin",psd="admin"",cn);
int num=Convert.ToInt32(comm.ExecuteScalar());//ExecuteScalar返回第一行第一例字符串
if(num<=0)//登录失败 说明查到这个人
{
Response.Write("<script>alert('没有该数据')</script>");
return;
}
else//登录成功
{
response.redirect("跳转页面路径")
}
楼主些登陆 查选一条就可以 查ds有点太浪费资源。
--------------------编程问答--------------------
SqlConnection cn = new SqlConnection("server=localhost;database=jtgl;user=sa;password=sa");
cn.open()
.....
int num=Convert.ToInt32(comm.ExecuteScalar());//ExecuteScalar返回第一行第一例字符串
cn.close()
不好意思 忘了打开关闭连接了 --------------------编程问答--------------------
SqlConnection cn = new SqlConnection("server=localhost;database=jtgl;user=sa;password=sa");
cn.open()
.....
int num=Convert.ToInt32(comm.ExecuteScalar());//ExecuteScalar返回第一行第一例字符串
cn.close()
不好意思 忘了打开关闭连接了 --------------------编程问答-------------------- 最基本的还是多看看书吧。。。。
补充:.NET技术 , ASP.NET