I would like to redirect admin if there is no record in table to the another form but I am doing something wrong in my code but i cant find. Could you please help me?
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
You meant to use an alias:
SELECT COUNT(Name) AS namecount FROM Users
instead of
SELECT COUNT(Name) WHERE namecount FROM Users
And:
reader1("namecount")
instead of:
reader1(namecount)
should be
SELECT COUNT(Name) AS namecount FROM Users
not
SELECT COUNT(Name) WHERE namecount FROM Users
精彩评论