newbie: accessing data in a datagrid

  • Thread starter Thread starter steve
  • Start date Start date
S

steve

Hi,

I want to count the number of occurences of a specific string that might
appear anywhere in a populated datagrid. How would i go about doing it?

I think that would be the best method since the string that populates the
dataset varies at runtime.

TIA
 
I think the better way would be to use COUNT in the SQL Query used to
fetch the data from your database.
Dim cn As New OleDbConnection
cn.ConnectionString = "Provider=SQLOLEDB;Data Source=DESKTOP;" & _
"Initial Catalog=Northwind;Trusted_Connection=Yes;"
cn.Open()
Dim cmd As OleDbCommand = cn.CreateCommand
' First Example - Count rows in Table
' SQL Query
cmd.CommandText = "SELECT COUNT (*) FROM Customers WHERE Country = 'UK'"
Dim intCount As Integer = CInt(cmd.ExecuteScalar)
' Display it
Label5.Text = "There are " & intCount.ToString & " entries for UK."
cn.Close()


All you need to do to tweak this for your purposes is replace the
hardcoded 'UK' in my example with the user input which will be taken at
runtime.

Ged
 
Firstly you are assuming that he wants the source data checked, this may
have been modified, secondly the OP stated he wanted to search for a string
'Anywhere' in the grid, this means multiple columns potentially.

If the data is bound to a table, then the OP could search this, failing that
the OP would have to iterate through the rows and columns of the grid
itself.

HTH

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top