如何在vb.net中进行具有计数,不同,位置,喜欢,子句的查询

时间:2019-01-10 15:22:21

标签: vb.net

    Dim cn As New OleDbConnection(My.Settings.connection)
    Dim SQLResult As Object
    Dim SQL As New OleDbCommand
    cn.Open()
    SQL.Connection = cn
    SQL.CommandText = "SELECT COUNT(*) FROM (SELECT DISTINCT StudentNumber FROM StudentTable)"
    SQLResult = SQL.ExecuteScalar
    MsgBox(SQLResult)

    cn.Close()

我想添加此WHERE节,例如'%“ + StudentNumberTextBox.Text +”%“

1 个答案:

答案 0 :(得分:0)

我使用表格适配器

SELECT        COUNT(*)
FROM            (SELECT DISTINCT StudentNumber FROM PresentStudentTable
WHERE        (StudentNumber = ?))

在表单代码上

TableTableAdapter.NameOfQuery(StudentNumberTextBox.Text)