两个解决方案可以是有趣:
- 直接链接数据库结果到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