兩個解決方案可以是有趣:
- 直接鏈接數據庫結果到DGV,便於更新非常好的,但少動行,如果這是需要
- 插入從查詢的數據行的你需要先定義DGV DataGridView2.Columns.Add()的列
1/
Using con As New SqlClient.SqlConnection("YOUR SQL CONNECTION STRING")
Dim sqlString As String = "SELECT * FROM Table WHERE intApprovedOvertime = 0 AND fkEmployee = pkEmployee"
con.Open()
Dim da As New SqlClient.SqlDataAdapter(sqlString, con)
Dim ds As New DataSet
da.Fill(ds, "Table")
DataGridView1.DataSource = ds.Tables("Table")
ds.Dispose()
da.Dispose()
SqlConnection.ClearPool(con)
End Using
2/
Using con As New SqlClient.SqlConnection("YOUR SQL CONNECTION STRING")
Dim command As New SqlCommand("SELECT * FROM Table WHERE intApprovedOvertime = 0 AND fkEmployee = pkEmployee", con)
Dim reader As SqlDataReader = command.ExecuteReader()
While reader.Read()
DataGridView1.Columns.Rows.Add(reader(0), reader(1))
End While
End Using
在你需要記住適應讀者數量2(x)的你需要添加到您的行值的數量。您也可以通過以下方式獲得某些列:
"SELECT Table.Name, Table.Position FROM Table WHERE intApprovedOvertime = 0 AND fkEmployee = pkEmployee"
可能會出現少許語法錯誤我沒有IDE與我哈哈。
爲什麼你只是不做正確的SQL請求:'SELECT * FROM Table WHERE intApprovedOvertime = 0' – Mederic
我以爲我可以爲每個員工做這件事,然後我不知道我怎麼能把它們放在一起並顯示它們。 – DIMPeteAsUsername
如果我這樣做的請求,它會檢索所有記錄,因爲我只想要來自特定員工 – DIMPeteAsUsername