How to get the data of specific rows?
Now, I used a control "DataGridView" to load the data from "local db". How can I read the data of singular row in the DataGridView?
This Question deserves the light of day so here is the process
I have a frmViewChildeTable that has a DataGridView when you click on a row with data you are taken to the frmDetailView
I will post the code for the appropriate process used in both forms
Here is code for the form with the DataGridView
Public Sub dgvChild_CellMouseClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvChild.CellMouseClick
If e.RowIndex = -1 Or e.ColumnIndex = -1 Then
'tbMessage.Text = "Col " & e.ColumnIndex & " ROW " & e.RowIndex'FOR TESTING
tbMessage.Text = "No Clicking Here"
Return
End If
Dim s1 As Integer
Dim str1 As String
Dim row As DataGridViewRow = dgvChild.Rows(e.RowIndex)
str1 = dgvChild.CurrentRow.Cells(0).Value.ToString
If str1 IsNot " " Then
If str1 Is " " Then
Return
End If
tbMessage.Text = "Text Sent to RTB"
s1 = CInt(row.Cells(0).Value)
gv_childInt = s1 'Set gv_childInt
frmDetailView.Show() '<========= LOOK
Close()
Return
End If
tbMessage.Text = "No Data Here"
End Sub
Here is the code that sows the detail view of the record in the DB
Please not the global variable gv_childInt
Private Sub readChildTableID()
Using conn As New SQLiteConnection($"Data Source = '{gv_dbName}';Version=3;")
conn.Open()
'The $ sign and '{String or Integer}' how to add variable to SQL Select Statement
'Must incorparate BOTH for SELECT to work
'=================================================================================
Using cmd As SQLiteCommand = New SQLiteCommand($"SELECT * FROM ChildTable WHERE CID = '{gv_childInt}'", conn)
Using rdr As SQLite.SQLiteDataReader = cmd.ExecuteReader
While rdr.Read()
tbMessageView.Text = rdr("CID").ToString
tbDispDateView.Text = rdr("cDispDate").ToString
tbTitleView.Text = rdr("cTitle").ToString
rtbEnterView.Text = rdr("cEntry").ToString
End While
rdr.Close()
End Using
End Using
conn.Close()
End Using
Me.Text = "Notebook Entry for " & tbDispDateView.Text
'CODE above sets text in Title Bar
'==================================
End Sub
I am not a C# coder but easy to use code converter