只是想知道是否有人可以提供帮助。
我首先需要使用sql表中的所有产品填充datagridview" sqlccmproduct"然后交叉引用" sqlinstructions"查看它是否存在,以及是否使用&#34填充列;是"或"否"无论是否被发现,希望附上的图片可以更容易。
非常感谢, 皮特
到目前为止,代码我已使用Board Column中填充的产品填充Datagridview并标记列:
DataGridView1.AutoGenerateColumns = True
cmd.CommandText = "SELECT product FROM [sqlccmproduct] ORDER BY product ASC"
Dim board_ranking_dataAdapter = New SqlDataAdapter(cmd.CommandText, con.ConnectionString)
Dim board_ranking_table As New DataTable()
board_ranking_table.Locale = System.Globalization.CultureInfo.InvariantCulture
board_ranking_dataAdapter.Fill(board_ranking_table)
Me.BindingSource1.DataSource = board_ranking_table
DataGridView1.DataSource = BindingSource1
disconnect()
DataGridView1.Columns(0).Width = 140
DataGridView1.Columns(1).Width = 140
DataGridView1.Columns(2).Width = 140
DataGridView1.Columns(3).Width = 140
DataGridView1.Columns(4).Width = 140
DataGridView1.Columns(5).Width = 140
DataGridView1.Columns(6).Width = 140
DataGridView1.Columns(7).Width = 140
DataGridView1.Columns(0).HeaderText = "Board:"
DataGridView1.Columns(1).HeaderText = "Prep:"
DataGridView1.Columns(2).HeaderText = "Pre-Coat:"
DataGridView1.Columns(3).HeaderText = "Pre-Oven:"
DataGridView1.Columns(4).HeaderText = "After-Coat:"
DataGridView1.Columns(5).HeaderText = "After-Oven:"
DataGridView1.Columns(6).HeaderText = "Board Coverage:"
DataGridView1.Columns(7).HeaderText = "Defect Coverage:"
DataGridView1.EnableHeadersVisualStyles = False
DataGridView1.Rows(0).Selected = True
'' NOW CHECK EACH ROW
For Each row As DataGridViewRow In DataGridView1.Rows
If Not row.IsNewRow Then
End If
Next
编辑:我已经让它在一行中工作,但是我的每一个"由于某种原因,行不起作用:
connect()
DataGridView1.AutoGenerateColumns = True
cmd.CommandText = "SELECT product FROM [sqlccmproduct] ORDER BY product ASC"
Dim board_ranking_dataAdapter = New SqlDataAdapter(cmd.CommandText, con.ConnectionString)
Dim board_ranking_table As New DataTable()
board_ranking_table.Locale = System.Globalization.CultureInfo.InvariantCulture
board_ranking_dataAdapter.Fill(board_ranking_table)
Me.BindingSource1.DataSource = board_ranking_table
DataGridView1.DataSource = BindingSource1
disconnect()
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataBindings.Clear()
DataGridView1.Columns(0).HeaderText = "Board:"
DataGridView1.EnableHeadersVisualStyles = False
'DataGridView1.Rows(0).Selected = True
DataGridView1.Columns.Add("prep", "Prep:")
DataGridView1.Columns.Add("precoat", "Pre-Coat:")
DataGridView1.Columns.Add("preoven", "Pre-Oven:")
DataGridView1.Columns.Add("aftercoat", "After-Coat:")
DataGridView1.Columns.Add("afteroven", "After-Oven:")
DataGridView1.Columns.Add("boardcoverage", "Board Coverage:")
DataGridView1.Columns.Add("defectcoverage", "Defect Coverage:")
DataGridView1.Columns(0).Width = 140
DataGridView1.Columns(1).Width = 140
DataGridView1.Columns(2).Width = 140
DataGridView1.Columns(3).Width = 140
DataGridView1.Columns(4).Width = 140
DataGridView1.Columns(5).Width = 140
DataGridView1.Columns(6).Width = 140
DataGridView1.Columns(7).Width = 140
'' NOW CHECK EACH ROW
For Each row As DataGridViewRow In DataGridView1.Rows
'If Not row.IsNewRow Then
connect()
cmd.CommandText = "SELECT count(*) from [sqlinstructions] where pcb = '" & row.Cells(0).Value.ToString & "' and type = 'Prep'"
cmd.Parameters.AddWithValue("@p1", row.Cells(0).Value.ToString)
Dim count1 = Convert.ToInt32(cmd.ExecuteScalar())
If count1 > 0 Then
row.Cells(1).Value = "Yes"
row.Cells(1).Style.BackColor = Color.Green
row.Cells(1).Style.ForeColor = Color.White
Else
row.Cells(1).Value = "No"
row.Cells(1).Style.BackColor = Color.Red
row.Cells(1).Style.ForeColor = Color.White
End If
cmd.CommandText = "SELECT count(*) from [sqlinstructions] where pcb = '" & row.Cells(0).Value.ToString & "' and type = 'Pre-Coat'"
cmd.Parameters.AddWithValue("@p2", row.Cells(0).Value.ToString)
Dim count2 = Convert.ToInt32(cmd.ExecuteScalar())
If count2 > 0 Then
row.Cells(2).Value = "Yes"
row.Cells(2).Style.BackColor = Color.Green
row.Cells(2).Style.ForeColor = Color.White
Else
row.Cells(2).Value = "No"
row.Cells(2).Style.BackColor = Color.Red
row.Cells(2).Style.ForeColor = Color.White
End If
cmd.CommandText = "SELECT count(*) from [sqlinstructions] where pcb = '" & row.Cells(0).Value.ToString & "' and type = 'Pre-Oven'"
cmd.Parameters.AddWithValue("@p3", row.Cells(0).Value.ToString)
Dim count3 = Convert.ToInt32(cmd.ExecuteScalar())
If count3 > 0 Then
row.Cells(3).Value = "Yes"
row.Cells(3).Style.BackColor = Color.Green
row.Cells(3).Style.ForeColor = Color.White
Else
row.Cells(3).Value = "No"
row.Cells(3).Style.BackColor = Color.Red
row.Cells(3).Style.ForeColor = Color.White
End If
cmd.CommandText = "SELECT count(*) from [sqlinstructions] where pcb = '" & row.Cells(0).Value.ToString & "' and type = 'After-Coat'"
cmd.Parameters.AddWithValue("@p4", row.Cells(0).Value.ToString)
Dim count4 = Convert.ToInt32(cmd.ExecuteScalar())
If count4 > 0 Then
row.Cells(4).Value = "Yes"
row.Cells(4).Style.BackColor = Color.Green
row.Cells(4).Style.ForeColor = Color.White
Else
row.Cells(4).Value = "No"
row.Cells(4).Style.BackColor = Color.Red
row.Cells(4).Style.ForeColor = Color.White
End If
cmd.CommandText = "SELECT count(*) from [sqlinstructions] where pcb = '" & row.Cells(0).Value.ToString & "' and type = 'After-Oven'"
cmd.Parameters.AddWithValue("@p5", row.Cells(0).Value.ToString)
Dim count5 = Convert.ToInt32(cmd.ExecuteScalar())
If count5 > 0 Then
row.Cells(5).Value = "Yes"
row.Cells(5).Style.BackColor = Color.Green
row.Cells(5).Style.ForeColor = Color.White
Else
row.Cells(5).Value = "No"
row.Cells(5).Style.BackColor = Color.Red
row.Cells(5).Style.ForeColor = Color.White
End If
cmd.CommandText = "SELECT count(*) from [sqlinstructions] where pcb = '" & row.Cells(0).Value.ToString & "' and type = 'Board Coverage'"
cmd.Parameters.AddWithValue("@p6", row.Cells(0).Value.ToString)
Dim count6 = Convert.ToInt32(cmd.ExecuteScalar())
If count6 > 0 Then
row.Cells(6).Value = "Yes"
row.Cells(6).Style.BackColor = Color.Green
row.Cells(6).Style.ForeColor = Color.White
Else
row.Cells(6).Value = "No"
row.Cells(6).Style.BackColor = Color.Red
row.Cells(6).Style.ForeColor = Color.White
End If
cmd.CommandText = "SELECT count(*) from [sqlinstructions] where pcb = '" & row.Cells(0).Value.ToString & "' and type = 'Defect Coverage'"
cmd.Parameters.AddWithValue("@p7", row.Cells(0).Value.ToString)
Dim count7 = Convert.ToInt32(cmd.ExecuteScalar())
If count7 > 0 Then
row.Cells(7).Value = "Yes"
row.Cells(7).Style.BackColor = Color.Green
row.Cells(7).Style.ForeColor = Color.White
Else
row.Cells(7).Value = "No"
row.Cells(7).Style.BackColor = Color.Red
row.Cells(7).Style.ForeColor = Color.White
End If
disconnect()
'End If
Next