如果表格中没有记录到另一个表单,我想重定向管理员,但我在我的代码中做错了但我找不到。你能帮我吗?
Private Sub frmlogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cmd As SqlCeCommand
Dim namecount As String
Dim con1 As SqlCeConnection
con1 = New SqlCeConnection("Persist Security Info=False;Data Source=.\database.sdf;Password=***********;File Mode=shared read")
con1.Open()
namecount = "SELECT COUNT(Name) WHERE namecount FROM Users"
cmd = New SqlCeCommand("SELECT COUNT(Name) WHERE namecount FROM Users", con1)
Dim reader1 As SqlCeDataReader = cmd.ExecuteReader()
While (reader1.Read())
If reader1(namecount) > 0 Then
'Redirect to Admin Form
Me.Hide()
frmadmin.Show()
Else
Me.Show()
End If
End While
End Sub
答案 0 :(得分:3)
您打算使用别名:
SELECT COUNT(Name) AS namecount FROM Users
而不是
SELECT COUNT(Name) WHERE namecount FROM Users
和
reader1("namecount")
而不是:
reader1(namecount)
答案 1 :(得分:0)
应该是
SELECT COUNT(Name) AS namecount FROM Users
不
SELECT COUNT(Name) WHERE namecount FROM Users