[AccessD] ADO Command object

Susan Harkins harkins at iglou.com
Tue Mar 11 13:28:23 CST 2003


I'm using it to connect to other databases on my local system -- including a
local SQL Server.

Function EditAccessNorthwind()
  Dim strConn As String
  Dim cmd As ADODB.command
  Dim rst As ADODB.Recordset
  strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=C:\Program Files\Microsoft Office\" & _
      "Office10\Samples\Northwind.mdb;"
  Set cmd = New ADODB.command
  With cmd
    .ActiveConnection = strConn
    .CommandText = "UPDATE Employees " & _
      "SET Title = 'Account Executive' " & _
      "WHERE Title = 'Sales Representative'"
    .Execute
  End With
End Function

Function EditSQLServerNorthwind()
  Dim strConn As String
  Dim cmd As ADODB.command
  Dim rst As ADODB.Recordset
  strConn = "Provider=SQLOLEDB;" & _
      "Server=(local);" & _
      "Initial Catalog=Northwind;" & _
      "Integrated Security=SSPI;"
  Set cmd = New ADODB.command
  With cmd
    .ActiveConnection = strConn
    .CommandText = "UPDATE Employees " & _
      "SET Title = 'Account Executive' " & _
      "WHERE Title = 'Sales Representative'"
    .Execute
  End With
  Set cmd = Nothing
End Function
Susan H.


> I think I misunderstood your question, you're asking why create a
connection
> object just to use that connection object for the .ActiveConnection of a
> Command?  If you're just using the currentproject.connection I can't
really
> see any advantage of first creating a Connection object and using that
> instead, seems to just add extra overhead.  But if you're connection
object
> is to any other backend than the CurrentProject.Connection you need to the
> Connection object to establish a valid connection first using the
> .ConnectionString etc....
>
> HTH,
> Chris Mackin
> www.denverdb.com
> Denver Database Consulting, LLC
>
>
> -----Original Message-----
> From: accessd-admin at databaseadvisors.com
> [mailto:accessd-admin at databaseadvisors.com]On Behalf Of Susan Harkins
> Sent: Tuesday, March 11, 2003 11:52 AM
> To: accessd at databaseadvisors.com
> Subject: Re: [AccessD] ADO Command object
>
>
> Hmmm... my understanding was that you needed the Command object to use
> CommandType, so how would using a Connection object to connect be an
> advantage with parameters?
>
> Susan H.
>
>
> > One major one is that the Command object has the parameters collection
> that
> > is vital to either passing parameters to a Stored Procedure or a
> > paramterized Query.
> >
> > Chris Mackin
> > www.denverdb.com
> > Denver Database Consulting, LLC
> >
> >
> > -----Original Message-----
> > From: accessd-admin at databaseadvisors.com
> > [mailto:accessd-admin at databaseadvisors.com]On Behalf Of Susan Harkins
> > Sent: Tuesday, March 11, 2003 10:56 AM
> > To: AccessD at databaseadvisors.com
> > Subject: [AccessD] ADO Command object
> >
> >
> > I see a lot of code that uses the Command object but connects via a
> > Connection object, when a Command object can do the same thing. I assume
> > this arrangement nets advantages -- can someone name a few?
> >
> > Susan H.
> >
> >
> >
> >
> > _______________________________________________
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> >
> >
> > _______________________________________________
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> >
>
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
>
>
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
>




More information about the AccessD mailing list