Problem #1. Transferring string data from the DataGridView1 (Record1 & Record2). If I put these variables into Textbox3 and TextBox5 and then use that in the WHERE clause, it works but is clumsly. I would prefer to work directly with these variables if I can get the syntax right.
Problem #2: Although DataGridView1 and DisplayTextBox fill with the appropriate data as a result of the search, when I select a row in DataGridview1 I get this error message:
DisplayTextBox.DataBindings.Add("Text", ds.Tables(0), "SectionText")
ARGUMENTEXCEPTION WAS UNHANDLED. This causes two bindings in the collection to bind to the same property. Parameter name: binding
Any help in sorting out these two issues would be greatly appreciated. My code:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim strSearch
strSearch = TextBox1.Text
Dim conn As New SqlConnection("XXX.)
Dim ds As New DataSet
conn.Open()
Dim adp As New SqlDataAdapter("Select FullDocNo, DocType, From FullDocuments WHERE CONTAINS(SectionText, ' """ & strSearch & """ ')", conn)
adp.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
conn.Close()
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
If Loading Or DataGridView1.SelectedCells.Count = 0 Then Exit Sub
Dim cell As DataGridViewCell = _
DirectCast(sender, DataGridView).SelectedCells.Item(0)
Dim rowindex As Integer = cell.RowIndex
Dim Record1 As String = DataGridView1.Rows(rowindex).Cells.Item(0).Value
Dim Record2 As String = DataGridView1.Rows(rowindex).Cells.Item(1).Value
'WOULD LIKE TO BE ABLE TO ELIMINATE THESE!
TextBox3.Text = Record1.ToString
TextBox5.Text = Record2.ToString
Dim conn As New SqlConnection("xxx)
Dim ds As New DataSet
conn.Open()
Dim adp As New SqlDataAdapter("SELECT SectionText FROM FullDocuments WHERE FullDocNo LIKE '" & TextBox3.Text & "' AND DocType LIKE '" & TextBox5.Text & "'", conn)
'CAN'T GET THIS VERSION TO WORK!
'Dim adp As New SqlDataAdapter("SELECT SectionText FROM FullDocuments WHERE FullDocNo LIKE 'Record1' AND DocType LIKE 'Record2'", conn)
adp.Fill(ds)
DisplayTextBox.DataBindings.Add("Text", ds.Tables(0), "SectionText")
conn.Close()
End Sub
End Class