private sub bok_click(byval sender as system.object, byval e as system.eventargs) handles bok.click '定义 dim olecn as new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=data.mdb") dim olecm as new oledbcommand("select * from login", olecn) dim olead as new oledbdataadapter dim olerd as oledbdatareader dim pd as boolean = false '定义boolean为后面错误处理使用 dim i as integer olecm = new oledbcommand("select * from login", olecn) '与数据库建立连接 olecn.open() olerd = olecm.executereader '循环判断与数据库中数据是否相同 do while olerd.read() for i = 0 to olerd.fieldcount - 1 if trim(tuser.text) = (olerd.item("帐号")) and trim(tpassword.text) = (olerd.item("密码")) then msgbox("成功登陆") pd = true exit sub end if next loop tuser.text = "" tpassword.text = "" tuser.focus() olerd.close() olecn.close() end sub