SQL Count不计算数据库中的数据行数

时间:2016-01-27 02:44:07

标签: sql sql-server vb.net count

我创建了以下sub来计算SQL Server表中数据出现次数,其中特定值出现在同一个表中。但是,它不计算我的要求。该子程序尝试对表中特定诊所名称的用户数进行计数。但是,它仅为0。

    Private Sub chUser()

    conn = New SqlConnection(conStr)
    conn.Open()
    myConn.clName = clNameDGV.SelectedCells.Item(0).Value
    MsgBox(myConn.clName)
    Dim comStr As String = "Select Count(*) as clName from Login_Detail Where Clinic_Name = '" & myConn.clName & "'"
    Dim comm As New SqlCommand(comStr, conn)
    Dim i As Integer = comm.ExecuteScalar()

    If i = 0 Then
        If MessageBox.Show("No User Information found for '" + clNameDGV.SelectedCells.Item(0).Value + "'." + vbNewLine + "Do you want to enter new user details ?", "No Users Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = vbYes Then
            Dim nf As New CreateUser
            nf.TopMost = True
            nf.ShowDialog(Me)
        End If
    Else
        Dim nf1 As New LoginForm
        nf1.TopMost = True
        nf1.ShowDialog(Me)

    End If
    conn.Close()

End Sub

0 个答案:

没有答案