改為:
成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供吐魯番網(wǎng)站建設(shè)、吐魯番做網(wǎng)站、吐魯番網(wǎng)站設(shè)計(jì)、吐魯番網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、吐魯番企業(yè)網(wǎng)站模板建站服務(wù),10多年吐魯番做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
sql = "insert into 表1 values(用戶名='" TextBox1.Text "' ,密碼='" TextBox2.Text "')"
Private Sub 提交_Click()
Dim stemp As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
stemp = "select * from user"
rs.Open stemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If Me!密碼 確認(rèn)密碼 Then
MsgBox "兩次輸入的密碼不一致,請(qǐng)重新輸入", vbExclamation, "Error"
Exit Sub
Else
stemp = "insert into user"
stemp = stemp "(用戶名,密碼,身份證號(hào))"
stemp = stemp " values('" Me!用戶名 "','" Me!密碼 "','" Me!身份證號(hào) "')"
DoCmd.RunSQL stemp1
Set rs = Nothing
End If
MsgBox "The information of register have saved already!", vbExclamation, "information"
End Sub
創(chuàng)建完相應(yīng)的用戶名,密碼控件之后,輸入以下代碼:
Imports System.Data.OleDb
Public Class Form1
Private Sub cmdok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdok.Click
Dim m_username As String
Dim m_userpwd As String
Dim cmd_result As MsgBoxResult
Dim m_da As New OleDbDataAdapter
Dim m_ds As New DataSet
Dim m_command As New OleDbCommand
Dim strsql As String
m_username = txtusername.Text
m_userpwd = txtuserpwd.Text
strsql = " select * from user_info where username='" m_username "' and userpwd='" m_userpwd "'"
OleDbConnection1.Open()
m_command.CommandType = CommandType.Text
m_command.CommandText = strsql
m_command.Connection = OleDbConnection1
m_da.SelectCommand = m_command
m_da.Fill(m_ds, "user_info")
If m_ds.Tables("user_info").Rows.Count 0 Then
cmd_result = MsgBox("歡迎登錄", MsgBoxStyle.OKOnly, "提示")
Else
MsgBox("登錄失敗,請(qǐng)確認(rèn)用戶名和密碼")
End If
End Sub
End Class
寫兩個(gè)函數(shù),一個(gè)檢測(cè)是否有重復(fù)用戶,第二個(gè)插入
檢測(cè)屬用戶是否存在
private function checkUser(byval uname as string) as boolean
dim sql as string = "select * from [user] where username=" uname
dim cmd as sqlcommand = new sqlcommand(sql,conn)
dim read as sqldatareader = cmd.excutereader
dim result as boolean = read.hasrows
cmd=nothing
return result
end function
新增用戶
private sub adduser(byval uname as string,byval password as string)
if checkUser(uname)
messagebox.show("用戶已存在")
exit sub
end if
try
dim sql as string = "insert into [user](username,password) values(@uname,@upass)"
dim cmd as sqlcommand = new sqlcommand(sql,conn)
cmd.parameters.add("@uname",sqldbtype.varchar).value=uname
cmd.parameters.add("@upass",sqldbtype.varchar).value=password
cmd.ExecuteNonQuery
cmd=nothing
messagebox.show("用戶添加成功!")
catch ex As Exception
messagebox.show("用戶添加失敗!" + ex.message)
end try
end sub