|
|
|
ขอโค้ดที่ เขียนเพื่อ login กับ database mysql แล้วเก็บชื่อ ฟิลด์ ที่ดึงออกจากดาต้าเบส แล้วเก็บไว้ในตัวแปร session หน่อยครับ |
|
|
|
|
|
|
|
ขออภัยครับผิดกระทู้ มึนซะงั้นผม
|
ประวัติการแก้ไข 2011-05-05 15:33:55 2011-05-05 15:34:41 2011-05-05 15:35:19 2011-05-05 15:35:58 2011-05-05 15:37:26 2011-05-05 15:40:42
|
|
|
|
Date :
2011-05-05 15:31:35 |
By :
Oakmat00 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (VB.NET)
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Page Language="VB" %>
<script runat="server">
Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim strConnString,strSQL As String
Sub btnLogin_Click(sender As Object, e As EventArgs)
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";Jet OLEDB:Database Password=;"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM member WHERE Username = '"& Me.txtUsername.Text &"' AND [Password] = '"& Me.txtPassword.Text &"' "
objCmd = New OleDbCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
IF intNumRows > 0 Then
Session("strUser") = Me.txtUsername.Text
Response.Redirect("Page1.aspx")
Else
Me.pnlLogin.Visible = False
Me.lblStatus.Visible = True
Me.lblStatus.Text = "Username/Password is wrong."
End IF
objConn.Close()
objConn = Nothing
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel id="pnlLogin" runat="server">
<asp:Label id="lblLogin" Text="Login." runat="server" />
<br />
<br />
<table border="1" style="width: 300px">
<tbody>
<tr>
<td>
<asp:Label id="lblUsername" runat="server" text="Username"></asp:Label></td>
<td>
<asp:TextBox id="txtUsername" runat="server" Width="120px"></asp:TextBox>
<asp:RequiredFieldValidator ID="ChkUsername" runat="server"
ControlToValidate="txtUsername" ErrorMessage="* Username"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label id="lblPassword" runat="server" text="Password"></asp:Label></td>
<td>
<asp:TextBox id="txtPassword" runat="server" Width="120px"
TextMode="Password"></asp:TextBox>
</td>
</tr>
</tbody>
</table>
<br />
<asp:Button id="btnLogin" onclick="btnLogin_Click" runat="server" Text="Login"></asp:Button>
<br />
</asp:Panel>
<asp:Label id="lblStatus" runat="server" visible="False"></asp:Label>
</form>
</body>
</html>
Go to : ASP.NET User Authentication/Login Form
ส่วน MySQL อ่านได้ที่
ASP.NET MySQL (MySql.Data.MySqlClient)
ASP.NET MySql.Data.MySqlClient
|
|
|
|
|
Date :
2011-05-05 17:27:58 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|