1 Replies - 1285 Views - Last Post: 02 July 2012 - 01:31 PM Rate Topic: -----

#1 purvabhilare1587  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 27-May 12

search for a string entered in column of datagridview in a text file

Posted 02 July 2012 - 02:27 AM

I want to search for a string entered in a column of a datagridview in a text file.If this string exists in the file then allow the user to enter it otherwise dont allow the user to enter the string.Also,since I am reading data from the database into the datagridview, I have not added columns to the datagridview using edit columns option. How do I do this in vb.net.I tried doing something like this:

 Private Sub DisplayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayButton.Click
        Dim cs As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;Data Source=C:\Users\technowin\Documents\Candidates.accdb;Jet OLEDB:Database Password=techno;"
        Dim sql As String

        If LastNameTextBox.Text = Nothing Then
            sql = "SELECT * FROM Infotable WHERE FirstName = '" & FirstNameTextBox.Text & "' AND MiddleName = '" & MiddleNameTextBox.Text & "'"
        Else
            sql = "SELECT * FROM Infotable WHERE LastName = '" & LastNameTextBox.Text & "' AND FirstName = '" & FirstNameTextBox.Text & "' AND Lastname = '" & LastNameTextBox.Text & "' "
        End If
        ' DataGridView1.Visible = True
        Dim connection As New OleDb.OleDbConnection(cs)
        dataadapter = New OleDb.OleDbDataAdapter(sql, connection)
        ds = New DataSet()
        connection.Open()


        'make the datagrid visible
        EditDataGridView.Visible = True
        dataadapter.Fill(ds, "Infotable")
        connection.Close()
        EditDataGridView.DataSource = ds
        EditDataGridView.DataMember = "Infotable"
       

    End Sub

 Private Sub EditDataGridView_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles EditDataGridView.CellContentDoubleClick

        If (e.ColumnIndex = 21) Then
            Dim text As String = File.ReadAll("D:\test1.txt")
            Dim index As Integer = text.IndexOf("")
            If index >= 0 Then
          
            End If
        End If
    End Sub



This post has been edited by Atli: 02 July 2012 - 02:46 AM
Reason for edit:: Fixed the [code] tags.


Is This A Good Question/Topic? 0
  • +

Replies To: search for a string entered in column of datagridview in a text file

#2 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 137
  • View blog
  • Posts: 829
  • Joined: 21-December 11

Re: search for a string entered in column of datagridview in a text file

Posted 02 July 2012 - 01:31 PM

search for a string in a text file:
You already know how to load txt file to string.
Dim text As String = File.ReadAll("D:\test1.txt")

Also you can use File.ReadAllLines function and loop through lines and check if each line contains string.
Dim txtLines() As String = File.ReadAllLines("D:\test1.txt")

So how to check if txt string contains your string?
1.You can use string.contains method
2.You can use like operator
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1