请教各位老师:VB6.0向access添加记录时,如何避免用户名重复?
Private Sub Command1_Click()On Error Resume Next
Call SJK(db)
If Text1 <> "" Then
Set RS = New ADODB.Recordset
'添加记录
strSQL = "select * from 用户表"
RS.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
RS.AddNew
RS!编号 = Text1.Text
RS!用户名 = Text2.Text
RS!密码 = Text3.Text
RS!权限 = Text4.Text
'RS!数量 = Text5.Text
'RS!单价 = Text6.Text
'Text7.Text = Text5.Text * Text6.Text
'RS!金额 = Text7.Text
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
'Text5.Text = ""
'Text6.Text = ""
MsgBox "添加成功"
RS.Update
RS.Close
cnn.Close
Set RS = Nothing
End If
End Sub