ado.net中登录页面的编码 [英] coding for login page in ado.net

查看:101
本文介绍了ado.net中登录页面的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个登录页面的编码页面或设计页面,在该页面中我们已经创建了数据库,或者我们已经想要在运行时登录时在数据库中插入了用户名或密码的值,因此必须在其中插入那些已经存在于数据库中的值

i want a coding or a design page for a login page in which where we are already make a database or we are already inserted the value of username or password in our database when we want to login in the runtime we have to inserted those value which are already in the database

推荐答案

您好,向您展示了一个示例如何完成此操作,我使用的数据库是Access 2003及其在ASP.NET中您可以在VC#中做同样的事情,只是您必须更改一些行才能让我显示

使用系统;
使用System.Data;
使用System.Configuration;
使用System.Collections;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;
使用System.Data.OleDb;
公共局部类登录:System.Web.UI.Page
{
受保护的void Page_Load(对象发送者,EventArgs e)
{
}
公共静态字符串getconnection()
{
return @"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = E:\ Registration form \ ASP.NET.mdb; Persist Security Info = False";
}
受保护的void Button1_Click(对象发送者,EventArgs e)
{
OleDbConnection con =新的OleDbConnection();
con.ConnectionString = getconnection();
con.Open();
字符串命令=从mytable中选择*,其中Myname = @ name和Password = @ pass";
OleDbCommand cmd =新的OleDbCommand(command,con);
cmd.Parameters.AddWithValue("@ name",txtusername.Text);
cmd.Parameters.AddWithValue("@ pass",txtpassword.Text);
OleDbDataReader dr = cmd.ExecuteReader();
如果(dr.Read()== true)
{
/*如果您使用的是vc#即GUI,那么您可以在此处在Response.Redirect位置添加msg框*/
Response.Redirect("Default2.aspx");
}
其他
{
txtusername.Text =未知用户";
}
con.Close();


}
}


如果您的数据库是SQL,则在OleDb jsut处添加SQL thats并使用名称空间
使用System.Data.SqlClient;

并将conncetion字符串更改为

SqlConnection connect =新的SqlConnection();
connect.ConnectionString =数据源= .;初始目录=母版;集成安全性=真";

其余方法相同

现在,如果您创建的表位于master数据库中,则在使用master else之前,您可以为您提供您的数据库名称.

一旦发现有用,就对我的答案进行评分

谢谢与问候
基数:rose:
hello am showing u an example how this thing is done the database i have used is Access 2003 and its in ASP.NET u can do the same thing in VC# only the thing is u have to change some lines let me show u

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public static string getconnection()
{
return @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Registration form\ASP.NET.mdb;Persist Security Info=False";
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = getconnection();
con.Open();
string command = "select * from mytable where Myname=@name and Password=@pass";
OleDbCommand cmd = new OleDbCommand(command,con);
cmd.Parameters.AddWithValue("@name", txtusername.Text);
cmd.Parameters.AddWithValue("@pass", txtpassword.Text);
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read() == true)
{
/*if ur using vc# i.e. GUI then u can add a msg box here at the place of Response.Redirect*/
Response.Redirect("Default2.aspx");
}
else
{
txtusername.Text = "unknown user";
}
con.Close();


}
}


and if ur database is SQL the at the place of OleDb jsut add SQL thats it and use the namespace
using System.Data.SqlClient;

and change the conncetion String to

SqlConnection connect = new SqlConnection();
connect.ConnectionString = "Data Source=.;Initial Catalog=master;Integrated Security=True";

The Remaining Method is same

now if the table u made is in master database then use master else in the place of master u can give ur database name.

Do Rate my answer once u find it useful

Thanks & Regards
Radix :rose:


看起来您需要与SQL交互才能进行身份验证的登录页面的示例代码:
http://www.daniweb.com/forums/thread24148.html [
Looks like you need a sample code for login page that interacts with SQL in order to authneticate:
http://www.daniweb.com/forums/thread24148.html[^]

If you need more, just use google... you will find ample material on it. :thumbsup:


Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        con.Open()
        cmd = New SqlCommand("select * from login where username='" + UsernameTextBox.Text.ToString + "' and password='" + PasswordTextBox.Text.ToString + "'", con)
        dReader = cmd.ExecuteReader()
        If dReader.Read = True Then
            MDIParent1.Show()
            Me.Hide()
            con.Close()
        Else
            MsgBox("sorry")
        End If
        con.Close()
    End Sub



tryyyyyyyyyyy



tryyyyyyyyyyy it


这篇关于ado.net中登录页面的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆