十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
写两个函数,一个检测是否有重复用户,第二个插入
成都创新互联是一家专业提供吉州企业网站建设,专注与成都网站设计、做网站、成都h5网站建设、小程序制作等业务。10年已为吉州众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。
检测属用户是否存在
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
改为:
sql = "insert into 表1 values(用户名='" TextBox1.Text "' ,密码='" TextBox2.Text "')"
Dim StrCon1 As String
Dim Con1 As New System.Data.OleDb.OleDbConnection
dim Cmd1 as System.Data.OleDb.OleDbCommand
dim tkSQL as String
Strcon1="Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" "D:\TEMP.ACCDB" "'"
'数据库连接字符串,指向您数据库
Con1.ConnectionString=StrCon1
Con1.Open
tkSQL="INSERT INTO UserList (UserName,PW) Values('" Me.TxtText1.Text "','" Me.TxtText2.Text "')"
'SQL语句,内容与您的数据库中对应
Cmd1=New System.Data.OleDb.OleDbCommand(tkSQL,Con1)
cmd1.ExecuteNonQuery
'执行
'以下向Combobox中添加Item
Dim DA1 As System.Data.OleDb.OleDbDataAdapter
dim DT1 as new System.Data.DataTable
Dim T1 As Integer
tkSQL="SELECT * FROM UserList"
DA1=New System.Data.OleDb.OleDbDataAdapter(tkSQL,con1)
DA1.Fill(DT1)
For T1=0 To dt1.Rows.Count-1
me.comboBox1.Items.Add(Dt1.Rows(T1)(0))
Next T1
Con1.Close
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
你去学习如何建立窗体,如何调出窗体,隐藏窗体,等等,就可以了。如果这个些不会,你就没法做成注册的。