例項123登入對話方塊

2021-10-06 09:34:17 字數 2060 閱讀 5192

1.開啟access2010,建立乙個資料庫login,另存乙個login.mdb,建立乙個usertable表,並錄入兩個資料用於測試

2.新增資料來源login.mdb

3.設計乙個窗體

form1,兩個lable,兩個textbox,兩個按鈕

4.form1中寫入**

imports system.data.oledb

public class form1

public function getconnection() as oledbconnection

return new oledbconnection(my.settings.loginconnectionstring)

end function

dim myconn as oledbconnection

private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load

'為了方便測試,測試完後就要刪除的

txtname.text = "abc"

txtpassword.text = "123"

end sub

private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click

if txtname.text = "" then

msgbox("必須輸入使用者名稱")

txtname.focus()

exit sub

end if

if txtpassword.text = "" then

msgbox("必須輸入口令")

txtpassword.focus()

exit sub

end if

myconn = getconnection()

myconn.open()

'這是關鍵1

dim strsql as string = "select * from usertable " & _

"where username='" & txtname.text.trim & "'" & _

" and password='" & txtpassword.text.trim & "'"

'dim strsql as string = "select * from usertable where username='abc' and password='123'"

dim mycomm as new oledbcommand(strsql, myconn)

dim mydatareader as oledbdatareader = mycomm.executereader

'這是關鍵2

if mydatareader.read = true then

dim fm as new form2

fm.showdialog()

else

msgbox("使用者句或口令不正確")

exit sub

end if

myconn.close()

end sub

private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click

me.close()

end sub

end class

Qt Creator登入對話方塊

實現功能 在彈出對話方塊中填寫使用者名稱和密碼,按下登入按鈕,如果使用者名稱和密碼均正確則進入主視窗,如果有錯則彈出警告對話方塊。實現原理 通過上節的多視窗原理實現由登入對話方塊進入主視窗,而使用者名稱和密碼可以用if語句進行判斷。實現過程 2.然後新建乙個qt designer form clas...

MFC 登入對話方塊

首先我們要確定在 寫 要想實現優先顯示並且能隨意退出程式這個功能最好的地方就是在initinstance 函式中,好了,現在我們開始寫程式。第一步,我們新建乙個單文件工程,工程名字就叫mainfram。第二步 我們設計乙個對話方塊資源,對話方塊資源id為idd dialog login,為它新增兩個...

對話方塊 訊息對話方塊

我們在使用windows系統的過程中經常會見到訊息對話方塊,提示我們有異常發生或提出詢問等。因為在軟體開發中經常用到訊息對話方塊,所以mfc提供了兩個函式可以直接生成指定風格的訊息對話方塊,而不需要我們在每次使用的時候都要去建立對話方塊資源和生成對話方塊類等。這兩個函式就是cwnd類的成員函式mes...