日期:2014-05-18  浏览次数:20475 次

用VS.NET2003写一个用户登陆程序
用户用密码登陆,希望详细点,我自己写的总有错,请大家指点
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim username, userpassword As String
  If Page.IsValid Then
  username = txtname.Text
  userpassword = txtpass.Text
  comdstr = "select * from users where (username='" & username & "') and (userpassword='" & userpassword & "')"
  comd = New SqlClient.SqlCommand(comdstr, objconn)
  objconn.open()
  Dim prord As SqlClient.SqlDataAdapter
  prord = comd.executereader
  If Not prord.read() Then
  Response.Write("<script language='jacascript'>alert('输入的用户名或密码错误');history.go(-1);</script>")
  Else
  Response.Redirect("host.aspx")
  End If
  End If
  End Sub

------解决方案--------------------
VB.NET code

   username   =   txtname.Text.Trim()
   userpassword   =   txtpass.Text.Trim() 
   comdstr ="select * from users where (username='" & username & "') and (userpassword='" & userpassword & "')" 
   comd   =   New   SqlClient.SqlCommand(comdstr,   objconn) 
   objconn.open() 
   Dim   dr As   SqlClient.SqlDataReader
   dr = comd.ExecuteReader(CommandBehavior.CloseConnection)
   If   Not   dr.read()   Then 
       Response.Write( " <script   language= 'jacascript '> alert( '输入的用户名或密码错误 ');history.go(-1); </script> ") 
   Else 
       Response.Redirect( "host.aspx ") 
   End   If

------解决方案--------------------
打错了,更正一下:
至于 "“read”不是“System.Data.SqlClient.SqlDataAdapter”的成员 ",从.net问世以来,SqlDataReader类一直就有一个Read()方法,我都用过N遍了,直到.net2008都有,VB不区分大小写,所以写read也没错.

你把我的代码放进去,我明明定义了Dim dr As SqlClient.SqlDataReader,你是不是又改成了SqlDataAdapter?