大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
改为:
成都创新互联公司专业为企业提供吐鲁番网站建设、吐鲁番做网站、吐鲁番网站设计、吐鲁番网站制作等企业网站建设、网页设计与制作、吐鲁番企业网站模板建站服务,10多年吐鲁番做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
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!密码 确认密码 Then
MsgBox "两次输入的密码不一致,请重新输入", vbExclamation, "Error"
Exit Sub
Else
stemp = "insert into user"
stemp = stemp "(用户名,密码,身份证号)"
stemp = stemp " values('" Me!用户名 "','" Me!密码 "','" Me!身份证号 "')"
DoCmd.RunSQL stemp1
Set rs = Nothing
End If
MsgBox "The information of register have saved already!", vbExclamation, "information"
End Sub
创建完相应的用户名,密码控件之后,输入以下代码:
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("登录失败,请确认用户名和密码")
End If
End Sub
End Class
写两个函数,一个检测是否有重复用户,第二个插入
检测属用户是否存在
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