主题:请问这一段代码哪里错了???
Try
Dim comstr As String
If CmbPurview.Text = "一般用户" Then '判断注册一般用户还是管理员
If TxtPassword.Text = TxtConfirmPassword.Text Then '确认密码填写无误
comstr = "insert into" & CmbPurview.Text & "values('" & TxtUserName.Text & "','" & CChar(TxtPassword.Text) & "')"
'定义一个sqlcommand类实例,并初始化
Dim mycom As New SqlCommand(comstr, SqlConnection1)
SqlConnection1.Open()
mycom.ExecuteNonQuery() '执行命令
SqlConnection1.Close()
MsgBox("添加成功!")
Else
MsgBox("两次密码输入不相同!")
TxtPassword.Text = ""
TxtConfirmPassword.Text = ""
TxtPassword.Focus() '把焦点落在密码的文本框
End If
Else
If TxtPassword.Text = TxtConfirmPassword.Text And TxtSuperPassword.Text = "applehuang" Then
comstr = "insert into" & CmbPurview.Text & "valuse('" & TxtUserName.Text & "','" & CChar(TxtPassword.Text) & "')"
Dim mycom As New SqlCommand(comstr, SqlConnection1)
SqlConnection1.Open()
mycom.ExecuteNonQuery()
MsgBox("添加成功!")
Else
MsgBox("密码错误!")
TxtPassword.Text = ""
TxtConfirmPassword.Text = ""
TxtSuperPassword.Text = ""
TxtPassword.Focus()
End If
End If
Catch ex As Exception
MsgBox("该用户已经存在,请选另一个用户名!") '异常处理,如有相同用户名存在就会出错
TxtUserName.Text = ""
TxtUserName.Focus()
Finally
SqlConnection1.Close()
End Try
生成没错误,但我点注册新的用户,它总是提示"该用户已经存在,请选另一个用户名"
Dim comstr As String
If CmbPurview.Text = "一般用户" Then '判断注册一般用户还是管理员
If TxtPassword.Text = TxtConfirmPassword.Text Then '确认密码填写无误
comstr = "insert into" & CmbPurview.Text & "values('" & TxtUserName.Text & "','" & CChar(TxtPassword.Text) & "')"
'定义一个sqlcommand类实例,并初始化
Dim mycom As New SqlCommand(comstr, SqlConnection1)
SqlConnection1.Open()
mycom.ExecuteNonQuery() '执行命令
SqlConnection1.Close()
MsgBox("添加成功!")
Else
MsgBox("两次密码输入不相同!")
TxtPassword.Text = ""
TxtConfirmPassword.Text = ""
TxtPassword.Focus() '把焦点落在密码的文本框
End If
Else
If TxtPassword.Text = TxtConfirmPassword.Text And TxtSuperPassword.Text = "applehuang" Then
comstr = "insert into" & CmbPurview.Text & "valuse('" & TxtUserName.Text & "','" & CChar(TxtPassword.Text) & "')"
Dim mycom As New SqlCommand(comstr, SqlConnection1)
SqlConnection1.Open()
mycom.ExecuteNonQuery()
MsgBox("添加成功!")
Else
MsgBox("密码错误!")
TxtPassword.Text = ""
TxtConfirmPassword.Text = ""
TxtSuperPassword.Text = ""
TxtPassword.Focus()
End If
End If
Catch ex As Exception
MsgBox("该用户已经存在,请选另一个用户名!") '异常处理,如有相同用户名存在就会出错
TxtUserName.Text = ""
TxtUserName.Focus()
Finally
SqlConnection1.Close()
End Try
生成没错误,但我点注册新的用户,它总是提示"该用户已经存在,请选另一个用户名"