当前位置: 代码迷 >> ASP.NET >> 求解决办法:用VB2005编了一个ACCESS访问的asp.net程序出错
  详细解决方案

求解决办法:用VB2005编了一个ACCESS访问的asp.net程序出错

热度:7984   发布时间:2013-02-25 00:00:00.0
求解决方法:用VB2005编了一个ACCESS访问的asp.net程序出错
用VB2005编了一个ACCESS访问的程序出错

这是vb.net课实验的:

主要代码如下: 
Dim mcon As New OleDbConnection 
Dim mycmd As New OleDbCommand 
' Dim reader As OleDbDataReader 

mcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=N:\VB实验7\JXDB.mdb;Persist Security Info=False" 
mcon.Open() 
mycmd.Connection = mcon 
mycmd.CommandText = "select * from usertab where userid='" & TextBox1.Text & "' and pwd='" & TextBox2.Text & "'" 


Dim reader As OleDbDataReader = mycmd.ExecuteReader 
While (reader.Read) 

If reader.Read = False Then '若无返回记录 
msg_label.Visible = True 
msg_label.Text = "登录失败!" 
TextBox1.Text = "" 
TextBox2.Text = "" 
TextBox1.Focus() 
Exit Sub 
Else 
Session("userid") = TextBox1.Text 
Response.Redirect("default1.aspx") 
msg_label.Text = "" 
End If 
End While 

textbox1与textbox2正常,access的userid与pwd数据都正常,为何有“用户代码未处理 OledbException 至少一个参数没有被指定值。”的出错,如何解决呢??

这行 mycmd.CommandText = "select * from usertab where userid='" & TextBox1.Text & "' and pwd='" & TextBox2.Text & "'" 有错吗?

  另外,请推荐一本学习VB。NET访问ACCESS的好书或好网站,小弟在此多谢了

------解决方案--------------------------------------------------------
While (reader.Read) 

End While 

换成,判断一个用户登录不用循环吧。
VB.NET code
reader.Read()If reader.HasRows Then   有这个用户Else   用户名或密码不正确!End If
  相关解决方案