关于行句柄无效的问题

yinsedeshi 2009-02-03 09:03:32
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ import namespace="system.data"%>
<%@ import namespace="system.data.oledb"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档 </title>
<script language="JavaScript1.2" src="mm_menu.js"> </script>

</head>
<body onLoad="MM_preloadImages('image/导航条_r1_c1_f2.gif');MM_preloadImages('image/导航条_r1_c2_f2.gif');MM_preloadImages('image/导航条_r1_c3_f2.gif');MM_preloadImages('image/导航条_r1_c4_f2.gif');MM_preloadImages('image/导航条_r1_c5_f2.gif');MM_preloadImages('image/导航条_r1_c6_f2.gif');MM_preloadImages('image/导航条_r1_c7_f2.gif')">
<table width="796" border="1">
<tr>
<td width="786" height="60"> <img src="banner.gif" width="786" height="60"> </td>
</tr>
<tr>
<td height="23">
<script language="JavaScript1.2">mmLoadMenus(); </script>
<script language="vb" runat="server">
Dim StrInf1$,StrInf2$
sub Button1_Click(obj as object,e as eventargs) '单击按钮子过程
If trim(TextNo.text)="" then StrInf1="用户名不得为空":exit sub
If IsNumeric(TextNo.text) = False Then StrInf1="用户名必须是数字":exit sub
If trim(TextPass.text)="" then StrInf2="密码不得为空":exit sub
If Len(trim(TextPass.text)) < 8 Then StrInf2="请输入8位密码":exit sub
Dim conn As OledbConnection,cd As New OleDbCommand,rd As OleDbDataReader

conn=New OledbConnection("Provider=Microsoft.jet.OleDb.4.0;data source=" & Server.MapPath("/aspnet/数据库/music.mdb"))
conn.Open() '打开数据库
cd=New OleDbCommand("select 用户名,密码,用户姓名 from 用户2 where 用户名='"& trim(TextNo.text) &"'And 密码='"& trim(TextPass.text) &"'",conn)
rd=cd.ExecuteReader()'定义Reader对象并取回数据
if rd.read() then
Session("用户名")=rd("用户名")
Session("用户姓名")=rd("用户姓名")
Response.redirect(Session("file") & "?歌曲编号=" & Session("歌曲编号"))
else
StrInf1="用户名或密码错误"
end if
conn.close() '关闭数据库
end sub
</script>
<tr>
<td> <form runat="server">
<table width="385" border="1" align="center">
<tr>
<td colspan="2"> <div align="center">登陆页面 </div> </td>
</tr>
<tr>
<td>用户名: </td>
<td> <asp:TextBox ID="TextNO" Columns="12" MaxLength="8" runat="server" />请输入用户名 <%=StrInf1%> </td>
</tr>
<tr>
<td>密码: </td>
<td> <asp:TextBox ID="TextPass" Columns="12" MaxLength="8" runat="server" TextMode="Password" /> <%=StrInf2%> </td>
</tr>
<tr>
<td colspan="2"> <asp:Button ID="Button1" runat="server" Text="登陆" OnClick="Button1_click" />
</td>
</tr>
</table>
</form> </td>
</tr>
</table>
<p>  </p>
</body>
</html>

当我输入正确的用户名和密码之后就会显示
行句柄无效。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: 行句柄无效。

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

请问高手我该怎么修改这段代码呀?我认为问题在Session("用户名")=rd("用户名")上。当我把这句去掉
然后把Response.redirect(Session("file") & "?歌曲编号=" & Session("歌曲编号"))改成Response.redirect("temp.aspx")
时候可以运行。但就是不知道怎么改。谁能帮帮我呀?

...全文
941 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧