none
datagridview where textbox= company name RRS feed

  • Question

  • i'm trying to show only rows with the same "c_name" as mytexbox.text.

    however i get a black dgv.

    when i specificly writing a name of a company in the script (changing mytextbox.text to a company name from my db), it works good. (look one row above the end of the script)

    what am i doing wrong?

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim provider As String
            Dim dataFile As String
            Dim connString As String
            Dim MyConn As OleDbConnection = New OleDbConnection
            Dim da As OleDbDataAdapter
            Dim ds As DataSet
            Dim tables As DataTableCollection
            Dim source1 As New BindingSource
    
    
            provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
            dataFile = global_db
            connString = provider & dataFile
    
            MyConn.ConnectionString = connString
            ds = New DataSet
            tables = ds.Tables
            da = New OleDbDataAdapter("Select * from [dialogs]", MyConn) 'Change items to your database name
            da.Fill(ds, "dialogs") 'Change items to your database name
            Dim view As New DataView(tables(0))
            
            
            Dim dv As DataView
            dv = New DataView(ds.Tables(0), "c_name = '" & MyTextBox.Text & "' ", "dialog_date Desc", DataViewRowState.CurrentRows)
            DataGridView1.DataSource = dv
    
    
    
        End Sub
    

    Monday, March 19, 2018 7:34 AM

Answers

  • I think it is better to clean up your code first from all things which are unused in the code. 

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim dt As New DataTable
            Dim da As New OleDbDataAdapter("Select * from [dialogs]", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & Global_db)
            da.Fill(dt)
            Dim dv As DataView
            dv = New DataView(dt, "c_name = '" & MyTextBox.Text & "' ", "dialog_date Desc", DataViewRowState.CurrentRows)
            DataGridView1.DataSource = dv
        End Sub

    Then be aware that the Col name in the dataview is case sensitive. 


    Success
    Cor

    • Marked as answer by noampro8 Monday, March 19, 2018 11:10 AM
    Monday, March 19, 2018 10:25 AM