Compare the values of an entire column of the DataGridView with a variable

3

I would like to compare the value of a string variable with an entire column of the DataGridView.

There is a code that looks at the whole column, more or less

textbox.Text = datagridview.columns("nome_da_coluna").value

Or do I have to create a loop for this query?

Dim sqlCmd As String = "SELECT COLUNA1, COLUNA2  FROM nome_da_tabela "
cnn = New SqlConnection(strCon)
cmd = New SqlCommand(sqlCmd, cnn)
Dim adpt As New SqlDataAdapter(sqlCmd, cnn)
Dim dts As New DataSet()

Try
    cnn.Open()

    adpt.Fill(dts, "nome_da_tabela")
    datagridview.DataSource = dts
    
asked by anonymous 02.02.2014 / 02:39

2 answers

3

You will have to implement a loop because your need is specific. The DataGridView implementation provides the operations required for row-by-column X-by-column manipulation.

In short, the ideal alternative is that you extend DataGridView and supply your need by offering the desired implementation as a new method as you suggested, let's look at:

seuDataDridView.columns("nome_da_coluna").value

However, I believe that storing the contents of all cells in this column is not a good practice, and may even cause memory overflow if there is too much data.

    
03.02.2014 / 12:44
0

One possibility is in SQL to have a field with concatenation of all column values, using, for example, FOR XML :

SELECT (SELECT COLUNA1 + ';' + COLUNA2 FROM nome_da_tabela FOR XML PATH(''))
    
11.07.2018 / 14:06