daveofgv
Well-known member
Hello All -
Simple / Quick Question - I am using VB.NET (2008)
I have a datagridview1 that is connected to a SQL database.... I want to click on a cell and have another datagridview2 fill with data in my select statement, however, it's not working correctly.
I can pull the data from SQL when I use a label and set it to the ProjectID number, however, I cannot select a cell in DataGridView1 and have that value pull the data from SQL to fill DataGridView2.
the Code I am having issues with is
Any help will be greatly appreciated.
Thanks in advanced
daveofgv
Simple / Quick Question - I am using VB.NET (2008)
I have a datagridview1 that is connected to a SQL database.... I want to click on a cell and have another datagridview2 fill with data in my select statement, however, it's not working correctly.
VB.NET:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
con.Open()
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
da = New OleDbDataAdapter("Select Field1 [NAME], Field2 [Count], Field3 [Doc Count], Field4 [Page Count], Field6 [Date Completed], Field7 [Status] from Files Inner Join Projects On Files.ProjectID = Projects.ProjectID WHERE Projects.ProjectID Like '%" & DataGridView1.SelectedCells.ToString & "%'", con)
da.Fill(dt)
DataGridView2.DataSource = dt.DefaultView
con.Close()
Label1.Text = DataGridView2.Rows.Count.ToString()
End Sub
I can pull the data from SQL when I use a label and set it to the ProjectID number, however, I cannot select a cell in DataGridView1 and have that value pull the data from SQL to fill DataGridView2.
the Code I am having issues with is
VB.NET:
da = New OleDbDataAdapter("Select Field1 [NAME], Field2 [Count], Field3 [Doc Count], Field4 [Page Count], Field6 [Date Completed], Field7 [Status] from Files Inner Join Projects On Files.ProjectID = Projects.ProjectID WHERE Projects.ProjectID Like '%" & DataGridView1.SelectedCells.ToString & "%'", con)
Any help will be greatly appreciated.
Thanks in advanced
daveofgv