分居VB.NET火鳥結果我有這個表:用逗號
電影
| Name | Genre |
| A | 1 |
| B | 2 |
| C | 3 |
| D | 4 |
| E | 5 |
流派
| Name | GenreID |
| Action | 1 |
| Sci-Fi | 2 |
| Horror | 3 |
| Comics | 4 |
| Romantic | 5 |
Film_Genre
| Film | Genre |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 2 | 1 |
| 2 | 4 |
| 3 | 2 |
VB.NET 2010年。 NET FrameWork 2.0源代碼:
Imports FirebirdSql.Data.FirebirdClient
Public Class Form1
Dim sCommand As FbBatchExecution
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.Columns.Add(0, "Part")
DataGridView1.Columns.Add(1, "Partn")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connection As New FbConnection("Database=e:\DBSCHOOL.FDB;User=SYSDBA;Password=masterkey;Dialect=3;ServerType=1")
connection.Open()
sCommand = New FbBatchExecution(connection)
AddHandler sCommand.CommandExecuted, AddressOf CmdE
'sCommand.SqlStatements.Add("CREATE TABLE Films (Name varchar(50), Genre int)")
'sCommand.SqlStatements.Add("insert into Films (Name, Genre) values ('A', 1);")
'sCommand.SqlStatements.Add("insert into Films (Name, Genre) values ('B', 2);")
'sCommand.SqlStatements.Add("insert into Films (Name, Genre) values ('C', 3);")
'sCommand.SqlStatements.Add("insert into Films (Name, Genre) values ('D', 4);")
'sCommand.SqlStatements.Add("CREATE TABLE Film_genre (Film varchar(50), Genre int)")
'sCommand.SqlStatements.Add("insert into Film_genre (Film, Genre) values (1, 2);")
'sCommand.SqlStatements.Add("insert into Film_genre (Film, Genre) values (1, 3);")
'sCommand.SqlStatements.Add("insert into Film_genre (Film, Genre) values (1, 4);")
'sCommand.SqlStatements.Add("insert into Film_genre (Film, Genre) values (2, 1);")
'sCommand.SqlStatements.Add("insert into Film_genre (Film, Genre) values (2, 4);")
'sCommand.SqlStatements.Add("insert into Film_genre (Film, Genre) values (3, 2);")
'sCommand.SqlStatements.Add("CREATE TABLE Genres (Name varchar(20), GenreID int)")
'sCommand.SqlStatements.Add("insert into Genres (Name, GenreID) values ('Action', 1);")
'sCommand.SqlStatements.Add("insert into Genres (Name, GenreID) values ('Sci-Fi', 2);")
'sCommand.SqlStatements.Add("insert into Genres (Name, GenreID) values ('Horror', 3);")
'sCommand.SqlStatements.Add("insert into Genres (Name, GenreID) values ('Comics', 4);")
'sCommand.SqlStatements.Add("insert into Genres (Name, GenreID) values ('Romantic', 5);")
sCommand.SqlStatements.Add("SELECT Name, LIST(Genre,';') from Films group by Name;")
sCommand.Execute()
connection.Close()
End Sub
Sub CmdE(ByVal sender As System.Object, ByVal e As CommandExecutedEventArgs)
If e.StatementType = 63 Then
DataGridView1.Rows.Clear()
Dim Table As List(Of DataGridViewRow) = New List(Of DataGridViewRow)
Dim FBDR As FbDataReader = e.DataReader
While FBDR.Read()
Dim adatok(FBDR.FieldCount - 1) As String
For i = 0 To FBDR.FieldCount - 1
adatok(i) = FBDR(i).ToString
Next
Table.Add(New DataGridViewRow())
Table(Table.Count - 1).CreateCells(DataGridView1, adatok)
End While
DataGridView1.Rows.AddRange(Table.ToArray)
End If
End Sub
End Class
我該如何解決我們得到的上述結果?
我想要得到這樣的結果:
| Film | Genres |
| A | Sci-Fi, Horror, Comics |
| B | Action, Comics |
| C | Sci-Fi |
感謝您的幫助,和抱歉,我的英語不好!
你的實際問題是什麼? – 2013-03-08 11:31:35
火鳥查詢,我怎麼能達到這個? 結果: '| |電影|流派| | A |科幻,恐怖,漫畫| | B |行動,漫畫| | C |科幻小說|' – Zserigta 2013-03-08 11:36:24