我有一个查询,当他们都知道这首歌并且状态已完成时,它会返回所选人员的歌曲名称列表。
当所有乐器都没有设置为“N/A”时,有没有办法只显示状态已完成的歌曲?
例如,假设表格内容如下。
BandieName SongName 乐器状态 Holly Wipeout Bells 完成 Holly Centenial N/A Complete 夏洛特消灭符号完成 夏洛特 Centenial N/A 完成
如果我从列表中选择Holly和Charlotte并运行查询,它将列出Wipeout和Centenial,因为它们都将这些歌曲的状态设为已完成;但是,我不希望它显示Centenial,因为该歌曲的所有选定人员的乐器都是N/A。
如果内容如下,并且我选择了其中的三首,我希望它显示所有三首歌曲,因为并非为该歌曲列出的所有乐器都是N/A。
BandieName SongName 乐器状态 Holly Wipeout Bells 完成 Holly Centenial N/A Complete 夏洛特消灭符号完成 夏洛特 Centenial N/A 完成 Ryan Wipeout Drum Complete Ryan Centenial Drum Complete
到目前为止,我的代码如下。
Protected Sub btnGetPlaylist_Click(sender As Object, e As System.EventArgs) Handles btnGetPlaylist.Click
Dim conn As SqlConnection = Nothing
Try
Dim connString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BandDatabase.mdf;Integrated Security=True;User Instance=True"
conn = New SqlConnection(connString)
Dim sqlBandies As String
Dim item As ListItem
For Each item In ListBoxBandies.Items
If item.Selected Then
Dim selectedBandies As String = item.Text
sqlBandies &= "'" & item.Text & "', "
End If
Next
Dim amountSelected As String = ListBoxBandies.Items.Count.ToString
Dim query As String = "select SongName from Learning where BandieName in (" + sqlBandies + " '') AND Status = 'Complete' group by SongName having count(distinct BandieName) = " + ListBoxBandies.GetSelectedIndices.Length.ToString
Dim cmd As SqlCommand = New SqlCommand(query, conn)
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim dt As DataTable = New DataTable()
dt.Load(dr)
GridViewPlaylist.DataSource = dt
GridViewPlaylist.DataBind()
Finally
conn.Close()
End Try
End Sub