Click to See Complete Forum and Search --> : Run SQL
Kiron
Dec 17th, 1999, 07:40 PM
Hello, i start to write module to use like a DB Engine. I create all kind of functions and all use the database object of "Micorosft ADO 3.51".
So i create a database object (DB As DataBase) and then i open it with OpenDataBase() function.
----The Problem-----
Now i want to run SQL statments like INSERT INTO, DELETE, UPDATE and all other SQL but i don't now how to do it with the database object.
Please help me out.
Kiron
MartinLiss
Dec 17th, 1999, 10:41 PM
Dim SQL As String
SQL = "DELETE FROM SavedSystems WHERE SystemName = " & "'" & sSysName & "'"
DB.Execute SQL, dbFailOnError
------------------
Marty
Elias
Dec 22nd, 1999, 11:21 AM
In a message you said:
Hello, i start to write module to use like a DB Engine. I create all kind of functions and all use the database object of "Micorosft ADO 3.51".
So i create a database object (DB As DataBase) and then i open it with OpenDataBase() function.
----The Problem-----
Now i want to run SQL statments like INSERT INTO, DELETE, UPDATE and all other SQL but i don't now how to do it with the database object.
Please help me out.
Kiron
*********************************************
I recommend you study up on your ADO code. First off, you should become familiar with the 3 objects of ADO: 1. The Connection Object, 2. The Command Object, 3. The Recordset object. Each is powerful in a unique way. I use the connection & recordset object the most. Also important is to know about connection strings, especially if you are ever planning to design 2 tier or n-tier server applications. ie the most basic would be the client-server application ( ie VB front end with a Access/SQL/Oracle back end ) Here is an example:
(this is easier if you have a reference to Microsoft ActiveX Data Objects 2.1 Library in your project ( ADO VB6.0) To do this, click on project, then references, then look for Microsoft ActiveX Data Objects 2.1 Library.
code example
dim cn as adodb.connection
dim rst as adodb.recordset
set cn = new adodb.connection
set rst = new adodb.recordset
cn.open strConnectionString ( There are many ways this string can be gotten easily. Email me for further details. )
with rst
'locktype & cursorlocation I am not so familiar with, but referr to help in VB for proper settings
.LockType = adLockBatchOptimistic
.CursorLocation = adUseServer
.open "Put your SQL statement here"
end with
You might ask why go through all that? Well, if you might operate over a different database backend than you did your prototype with, then all you would have to do is change your connection string and make sure your SQL statements are using the correct syntax for the new backend database, and you are cooking without any additional code changes. Good luck.
-Elias
Clunietp
Dec 22nd, 1999, 11:36 AM
ELIAS
I hate to tell you that you wasted all of your time writing that beautiful reply, but I'm afraid that Kiron wanted to know about DAO, not ADO. It looks like he transposed the letters. OOPS! :) I can tell because ADO does not have a DBEngine object, or a OpenDatabase method, or a Database object. DAO has all of these.
Sorry man!
Kiron
Dec 23rd, 1999, 02:45 AM
Hello, first thank you all for the answers :) thank you very much.
now I do mean about DAO because I gona write a program that use only one database and this database is in the same computer as the program will be so that's way i didn't use any connections and stuff.
The second this is i didn't use the DBEngine of Microsoft, i write something like the [DoCmd] object of Access that know to run SQL, open RecordSet and more. I can send to you the module when i done.
and again thank you for the answers.
Bye~ :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.