Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Lin100
Yak Posting Veteran
70 Posts |
Posted - 2006-09-21 : 23:09:33
|
Access 2002 and SQL 2000 ServerCommand Versus Connection.Below are ADO codes for command and for connection. Both works.Under which condition should Command be used ?Under which condition should Connection be used ?/////////////////////////////////////////////////////////////////////////Private Sub User_Login_Using_SQL_String_1() Dim cmd As ADODB.Command Set cmd = New ADODB.Command Set cmd.ActiveConnection = CurrentProject.Connection cmd.CommandText = "UPDATE User_Account SET Last_Access_Date = Now() " _ & "WHERE Name = '" & Forms!Main_Login!User_Name & "';" cmd.Execute 'It Execute SynchronouslyEnd Sub/////////////////////////////////////////////////////////////////////////Private Sub User_Login_Using_SQL_String_2() Dim Str_SQL As String Dim cnThisConnect As ADODB.Connection Set cnThisConnect = CurrentProject.Connection Str_SQL = "UPDATE User_Account SET Last_Access_Date = Now() " _ & "WHERE Name = '" & Forms!Main_Login!User_Name & "';" cnThisConnect.Execute Str_SQLEnd Sub |
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2006-09-21 : 23:25:31
|
Commands are good if you want to run stored procs with parameters. Although you can execute a stored proc directly against the connection object in ADP's:cnThisConnect.proc_MyProcedure param1, param2 etc etc.But this may be undocumented, so try at your own peril......Tim |
 |
|
|
|
|