我的 Access 数据库数据如下所示:
srno likes
user 1 001,002,003
user 2 001,004,005,007
user 2 001,007,009,001
etc
我想计算likes
列中每个单独的值(即001
,002
等)出现在表中的次数。
我使用了这段代码:
cnn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data\Acetech.mdb"))
cnn.Open()
msg = "SELECT COUNT(001) FROM (productfeedback) WHERE three like '001' OR second like '001' "
cmd = New OleDbCommand(msg, cnn)
str = cmd.ExecuteScalar()
cnn.Close()
它应该显示001 4
:
If str Is DBNull.Value Then
Label12.Text = "0"
Else
Label12.Text = Format(CStr(TextBox2.Text)) & Convert.ToInt32(str)
End If