1 Replies - 15190 Views - Last Post: 01 July 2013 - 05:58 AM Rate Topic: -----

#1 mrkey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 13

how to "adodb in visual basic 2010"

Posted 01 July 2013 - 05:25 AM

Hello guys sorry for the stupid question. In VB 2010 how do you connect to the database using the legacy ADO like in the VB6.0.

My codes here is applicable in VB6.0, this is what I used to connect and do some query.

this is in the module.
Public DBCon As ADODB.Connection
Public Concom As ADODB.Command
Public DBrs As ADODB.Recordset

Public Sub DBConnect()

    Set DBCon = New ADODB.Connection
    Set Concom = New ADODB.Command
    Set DBrs = New ADODB.Recordset
    DBCon.ConnectionString = "Provider=Microsoft.jet.oledb.4.0; Data Source=" & App.Path & "\Database\HRIS.mdb"
    Concom.ActiveConnection = DBCon
End Sub

Public Sub SQLcmd(SQLstatement As String)
    Concom.CommandText = SQLstatement
    Set DBrs = Concom.Execute
End Sub

after that I just call the dbconnect to every form, then use the sqlcmd for the query like this.

SQLcmd "select * from tblePerson where Fname = " & txtSearch & ""

I tried to do this in vb2010 but it just won't work. I search over google about adodb in vb.net but i got confused. Sorry, I just don't know where to start and what to do. Any help would greatly be appreciated. Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: how to "adodb in visual basic 2010"

#2 DarenR   User is offline

  • D.I.C Lover

Reputation: 593
  • View blog
  • Posts: 3,823
  • Joined: 12-January 10

Re: how to "adodb in visual basic 2010"

Posted 01 July 2013 - 05:58 AM

dim connstring as string = something
dim sconnect as new sqlconnection(connstring)
dim scmd as sqlcommand =  new sqlcommand(sconnect)

or soemthing like the following

  Dim sb As New System.Text.StringBuilder
        Dim c As Integer = 0
        Dim dt As New DataTable
        Dim da As New Data.OleDb.OleDbDataAdapter
        Dim cmdBuilder As New OleDb.OleDbCommandBuilder
        Dim cmd As New OleDb.OleDbCommand
        cmd.CommandType = CommandType.TableDirect
        dsn = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
        "Data Source=c:\temp\ss.xls;" + _
        "Extended Properties="""""
        cmd.CommandText = "Select * From [something]"
        cmd.Connection = New OleDb.OleDbConnection(dsn)
        da.SelectCommand = cmd
        cmdBuilder.DataAdapter = da

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1