查看: 788|回复: 5
|
帮忙,asp.net新手 (login问题)
[复制链接]
|
|
现在我要写一个asp.net login function.
但是应该connection有问题,请帮忙看看哪里需要改正。
login page
Protected Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
Dim conn
Dim ssql
Dim rsverify
Dim strUsrid As String = txtuser.Text
Dim strPwd As String = txtpass.Text
conn = Server.CreateObject("adodb.connection")
conn.open("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
If txtuser.Text <> "" Then
If txtpass.Text <> "" Then
ssql = "Select * from tbl_login where username = '" & txtuser.Text & "' and password = '" & txtpass.Text & "'"
rsverify = Server.CreateObject("adodb.recordset")
rsverify.open(ssql, conn, 3, 3)
If rsverify.EOF Then
Session("txtuser") = ""
lbl1.Text = "Sorry, email address or password error"
Else
If strPwd = rsverify("txtpass.text") Then
Session("txtuser") = rsverify.Fields("username")
Session("txtpass") = rsverify.Fields("password")
conn.execute(ssql)
lbl1.Text = "Success"
Else
Session("txtuser") = ""
lbl1.Text = "Sorry, username or password error"
End If
rsverify.Close()
rsverify = Nothing
End If
Else
lbl1.Text = "Sorry, password can not be blank"
End If
Else
lbl1.Text = "Sorry, username can not be blank"
End If
End Sub
End Class
web config
<configuration>
<appSettings/>
<connectionStrings>
<add name="ConnectionString" = connectionString"
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" strict="false" explicit="true"/>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
</namespaces>
</pages>
<authentication mode="Windows"/>
</system.web>
</configuration>
请问哪里有错误。。。
[ 本帖最后由 Stylehoong 于 27-2-2007 07:26 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 27-2-2007 12:34 AM
|
显示全部楼层
你应该先提供 error message, 这样大家才容易为你判断错误在那里. 另外你的 connection string post 不完整. |
|
|
|
|
|
|
|

楼主 |
发表于 27-2-2007 07:19 AM
|
显示全部楼层
原帖由 goatstudio 于 27-2-2007 12:34 AM 发表
你应该先提供 error message, 这样大家才容易为你判断错误在那里. 另外你的 connection string post 不完整.
error message是以下:
The component 'adodb.connection' cannot be created. Apartment threaded components can only be created on pages with an <%@ Page aspcompat=true %> page directive.
应该是connection有错。。。。但是不知道怎么改。(我是用sql server 2005做database) |
|
|
|
|
|
|
|
发表于 27-2-2007 09:32 AM
|
显示全部楼层
你是用 asp.net 吗? 为什么你的连接资料库的 code 是 asp 的 code? |
|
|
|
|
|
|
|

楼主 |
发表于 27-2-2007 01:55 PM
|
显示全部楼层
原帖由 goatstudio 于 27-2-2007 09:32 AM 发表
你是用 asp.net 吗? 为什么你的连接资料库的 code 是 asp 的 code?
yaya,我是用asp.net,但是不熟asp.net,所以才使用这code。
请问这样要怎么更改? |
|
|
|
|
|
|
|
发表于 27-2-2007 02:17 PM
|
显示全部楼层
原帖由 Stylehoong 于 27-2-2007 01:55 PM 发表
yaya,我是用asp.net,但是不熟asp.net,所以才使用这code。
请问这样要怎么更改?
你应该去寻找关于 ASP.NET 资料库的资料.
去这里看看: www.asp101.com, 里面有 ASP 和 ASP.NET的资料. |
|
|
|
|
|
|
| |
本周最热论坛帖子
|