当前位置: 代码迷 >> ASP.NET >> System.InvalidCastException: 从类型“OleDbDataReader”到类型“String”的转换无效。该如何解决
  详细解决方案

System.InvalidCastException: 从类型“OleDbDataReader”到类型“String”的转换无效。该如何解决

热度:5566   发布时间:2013-02-25 00:00:00.0
System.InvalidCastException: 从类型“OleDbDataReader”到类型“String”的转换无效。
源文件
If TextBox1.Text = "" Or TextBox2.Text = "" Then
  Response.Write("<script>alert('用户名或密码不能为空!');history.back();</script>")
  TextBox1.Focus()
  Else
  conn.Open()
  '用户登录
  If DropDownList1.SelectedValue = "学生" Then
  Dim str As String
  str = "Select username,password from [user] where username='" & Trim(TextBox1.Text) & "' and password='" & Trim(TextBox2.Text) & "'"
  Dim cmd As New Data.OleDb.OleDbCommand(str, conn)
  Dim myreader As Data.OleDb.OleDbDataReader
  myreader = cmd.ExecuteReader()
  If (myreader.Read()) Then
  Dim str1 As String
  str1 = "Select username,password from [user] where username='" & Trim(TextBox1.Text) & "' and password='" & Trim(TextBox2.Text) & "'"
  Dim cmd1 As New Data.OleDb.OleDbCommand(str1, conn)
  Dim myreader1 As Data.OleDb.OleDbDataReader
  myreader1 = cmd1.ExecuteReader()
  Dim aa As Object
  aa = myreader1
  Session("name") = TextBox1.Text
  Response.Redirect("success.aspx?id=" & Server.UrlEncode(TextBox1.Text) & "& pas=" & Server.UrlEncode(aa))
  'Response.Redirect("userInfo.aspx?name=" & Server.UrlEncode(TextBox1.Text))
  Else
  Response.Write("<script>alert('用户不存在或密码错误!');history.back();</script>")
  End If
  Else
  If DropDownList1.SelectedValue = "老师" Then
  Dim str1 As String
  str1 = "Select admin_name,admin_pass from [adminuser] where admin_name='" & Trim(TextBox1.Text) & "' and admin_pass='" & Trim(TextBox2.Text) & "'"
  Dim cmd1 As New Data.OleDb.OleDbCommand(str1, conn)
  Dim myreader1 As Data.OleDb.OleDbDataReader
  myreader1 = cmd1.ExecuteReader()
  If (myreader1.Read()) Then
  Session("mem") = TextBox1.Text
  Response.Redirect("admin.aspx")
  Else
  Response.Write("<script>alert('用户不存在,请注册!');history.back();</script>")
  End If
  End If
  End If
  End If




aa = myreader1
行 47: Session("name") = TextBox1.Text
行 48: Response.Redirect("success.aspx?id=" & Server.UrlEncode(TextBox1.Text) & "& pas=" & Server.UrlEncode(aa))
行 49: 'Response.Redirect("userInfo.aspx?name=" & Server.UrlEncode(TextBox1.Text))
行 50: Else
 

源文件: F:\任叶毕业设计\网络0601任叶\系统源程序\login.aspx.vb 行: 48 

堆栈跟踪: 


[InvalidCastException: 从类型“OleDbDataReader”到类型“String”的转换无效。]
  Microsoft.VisualBasic.CompilerServices.Conversions.ToString(Object Value) +591
  _Default.Button2_Click(Object sender, EventArgs e) in F:\任叶毕业设计\网络0601任叶\系统源程序\login.aspx.vb:48
  System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
  相关解决方案