'selectConnection' narrows from 'Object' to 'System.Data.OleDb.OleDbConnection

Please help he for this code and this error

Error 1 Overload resolution failed because no accessible 'New' can be called without a narrowing conversion: 'Public Sub New(selectCommandText As String, selectConnection As System.Data.OleDb.OleDbConnection)': Argument matching parameter 'selectConnection' narrows from 'Object' to 'System.Data.OleDb.OleDbConnection'. 'Public Sub New(selectCommandText As String, selectConnectionString As String)': Argument matching parameter 'selectConnectionString' narrows from 'Object' to 'String'. F:\project\B-tech\FirstVBproject\LMSapp\LMSapp\book\updatecate.vb 89 23 LMSapp

Dim int As Integer
Dim cnnOLEDB As New OleDbConnection
Dim cmdOLEDB As New OleDbCommand
Dim rdr1 As OleDbDataReader
'Dim dataadp As New OleDbDataAdapter
Dim cmdInsert As New OleDbCommand
Dim cmdUpdate As New OleDbCommand
Dim cmdDelete As New OleDbCommand
Dim csearce As String
Dim cmdsearch As New OleDbCommand

Dim cnn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\project\B-tech\FirstVBproject\LMSapp\LMSapp\Library2.accdb")

Private Sub BunifuFlatButton3_Click(sender As Object, e As EventArgs) Handles BunifuFlatButton3.Click



        Dim search As String = srctxt.text
        Dim dataT As New DataTable
        Dim dataS As New DataSet
        Dim dataadp As New OleDbDataAdapter
        dataadp = New OleDbDataAdapter("select * from Category where ID like '%" & srctxt.text & "%'", cnn)
        'dataadp = New OleDbDataAdapter("select * from Category where ID like '%" & srctxt.text & "%'", cnnOLEDB)
        DataGridView1.DataSource = dataT.DefaultView

    Catch ex As Exception

    End Try
end sub()

1 answer

  • answered 2018-04-17 04:18 Ronnie Jimenez

    If you want to load the data into datagrid view. You can edit my code below.

        Dim ConnString As String = "provider= Microsoft.ACE.OLEDB.12.0; Data Source=D:\Users\rjimenez\Documents\QAdatabase.mdb"
        Dim SQLString As String = "SELECT Username, User FROM QAForHA where User='" & txtUser.Text & "'"
        Dim OleDBConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnString11)
        Dim DataSet As New DataSet()
        Dim OleDbDataAdapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString11, OleDBConn11)
        OleDbDataAdapter.Fill(DataSet, "QAForHA")
        DgvUsernameHA1.DataSource = DataSet.Tables("QAForHA")