PDA

View Full Version : access databases



morganrobin
11-11-2002, 01:37 PM
Can anyone help me out with any info on how to add access database tables to another table using install script. I am fairly new to install shield and know how to include a database but that is about as far as I have gotten. We have several database tables that we need to merge into a clients database. Both are access databases. Any info would be helpful....thanks....robin:confused:

iOnline
11-12-2002, 12:49 AM
you can connect to the database through installscipt using ADO objects.Later can create tables and populate them with data ..

Here is a sample code..
szADOObjID = "ADODB.Connection";
set pADOObj = CreateObject(szADOObjID);
szConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=<path>\\database.mdb;" +
"User Id=admin;" +
"Password=" ;
try
pADOObj.Open( szConnectionStr );
szSql = "create table tablename(userid varchar(50),username varchar(50))";
pADOObj.Execute(szSql);
catch
MessageBox(Err.Description,SEVERE);
endcatch;

HTH..

morganrobin
11-13-2002, 03:53 PM
Thanks for responding to my post. Do you have time for a little more chat? I am not sure how to call the connection from Install Shield or Create the tables. I would appreciate any more info you can give....Thanks....robin

iOnline
11-14-2002, 12:25 AM
Here is a sample code that will work in Developer 7 project..
Declaration for the function ;
prototype ConnectToAcsDatabase(HWND);
Defination for the function starts from here
function ConnectToAcsDatabase(hMSI)
STRING szConnectionStr,szADOObjID,szSql ;
OBJECT pADOObj;

begin
szADOObjID = "ADODB.Connection"; connection object ID
set pADOObj = CreateObject(szADOObjID); create an connection object using ADO
szConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=F:\\TestAcs\\aboutdelphi.mdb;" +
"User Id=admin;" +
"Password=" ; connection string
Here data source is the path of your mdb file

try
pADOObj.Open( szConnectionStr ); Open the connection
szSql = "create table sonata(userid varchar(50),username varchar(50))"; can give any sql command for execution
pADOObj.Execute(szSql); execute the sql string
catch
MessageBox(Err.Description,SEVERE);
endcatch;

end;

You can call this function using a Custom Action..
For example
declaration

export prototype CallingFunction(HWND)

defination
function CallingFunction(hMSI)
begin
ConnectToAcsDatabase(HWND);
end;
Create a custom action for CallingFunction and execute it at any sequence..
HTH..