连接数据库的小问题。求帮助。。
前台代码↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.style1
{
height: 106px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="style1">
用户名<asp:TextBox ID="username" runat="server" Height="22px"></asp:TextBox>
密码 <asp:TextBox ID="userpass" runat="server" Height="22px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" Height="26px" Width="56px" />
<br /><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
后台代码。。。
Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'创建数据库连接↓
Dim conn As SqlConnection
Dim comd As SqlCommand
Dim datar As SqlDataReader
conn = New SqlConnection("Server=local;user id=sa;pwd=123321;database=liu")
comd = New SqlCommand("Select * form 用户 where 用户名='" & username.text & "' and 密码='" & userpass.text & "'", conn)
conn.Open()
datar = comd.ExecuteReader()
If datar.Read() Then
Session("curruser") = datar("code").ToString()
Session("dispuser") = datar("useridspname").ToString()
Session("logintime") = New()
Response.Redirect("index.aspx")
Else
Label1.text = "对不起密码或名称错误~!"
End If
End Sub
End Class
提示的是未声明username 和未声明userpass 还有未声明 label1...之类的。。还求解释下
If datar.Read() Then
Session("curruser") = datar("code").ToString()
Session("dispuser") = datar("useridspname").ToString()
Session("logintime") = New()
Response.Redirect("index.aspx")
这段代码意思~~~谢谢了~~!!
[解决办法]
你前台页面最上面没有
<%@ Page .... %>
吗?需要这个的,才能跟后台关联起来