0
Dim elem As String
elem = "College"
Dim conn As New SqlClient.SqlConnection
With conn
.ConnectionString = ("SERVER=ANINGDZTS-PC;DATABASE=AEVS_2013;Trusted_Connection = yes;")
.Open()
End With
Dim cmd As New SqlClient.SqlCommand
With cmd
.CommandText = "SELECT [PositionID],[Position],[Partylist],[Department],[Fullname],[Lvl],[Section],[Votes] FROM tbl_Cand WHERE [Department] = '" & elem & "'"
.CommandType = CommandType.Text
.CommandTimeout = 30
.Connection = conn
End With
Dim dt As New DataTable
dt.Load(cmd.ExecuteReader)
With DataGridView1
.AutoGenerateColumns = True
.DataSource = dt
End With
vvv()
cmd.Dispose()
cmd = Nothing
conn.Dispose()
conn = Nothing
這是我的代碼查看所有候選人,但我只想獲得累積選票最多的人的名字和投票。例如,在總統中,我有2個候選人,但我只想看看誰擁有最高的累積選票。獲取數據庫中的最大值
你的問題是什麼? – JohnFx
你只是需要修改SQL –