2017-04-13 44 views
0

我有从dbo.tblAttendanceTimes一个DataGridView其显示Data使用tblAttendanceTimesTableAdapter.GetDataBy(intEmployee)显示SQL数据库中没有要过滤的列的特定数据。 (VB.NET)

所以,很显然它会显示所有Data所选雇员。

雇员分成3组。我想要做的是在[intApprovedOvertime]Columndbo.tblAttendanceTimes中显示值为0的所有记录,以查看我正在查看的特定群组。

刚刚与GetDataBy(intEmployee)正在难,没有[intAttendanceGroup]ColumnTable或者我可以只GetDataBy(intAttendanceGroup)

目前我所有的pk Values`为员工组中,但我努力检索该员工的所有记录显示他们,然后执行下一个员工,并添加到以前显示。

我希望我有道理,请索取任何您想要的其他信息。

+0

为什么你只是不做正确的SQL请求:'SELECT * FROM Table WHERE intApprovedOvertime = 0' – Mederic

+0

我以为我可以为每个员工做这件事,然后我不知道我怎么能把它们放在一起并显示它们。 – DIMPeteAsUsername

+0

如果我这样做的请求,它会检索所有记录,因为我只想要来自特定员工 – DIMPeteAsUsername

回答

0

两个解决方案可以是有趣:

  • 直接链接数据库结果到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与我哈哈。