开发者

What is wrong with count [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜