Hi ,
I want to insert data into tables in a SQL database.The database and the tables, are created using sql scripts run from the installshield. Could any one of you help me how to insert data into tables using insert scripts(sql) into the tables. Please consider this as very urgent.
Thanks,
Shajil.
This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
How to insert dat into database(table) SQL
Started by
shajilr
, Oct 18 2002 08:25
3 replies to this topic
Posted 18 October 2002 - 15:37
Are you saying you already have a DB and would like to install it and attach it? Or, are you wondering how to read data coming in and have it put into the proper table?
If it's the former, what I do is
A. Install the already created database into the TARGETDIR
B. Append a batch file with
Note: the go are not really needed after SQL 6(?), but I put them in anyway just in case.
C. Run the batch file
If you give me a little more information, I may be able to help more.
If it's the former, what I do is
A. Install the already created database into the TARGETDIR
B. Append a batch file with
Code Sample |
szLine1='exec sp_attach_db "DataBase 1", "'+TARGETDIR + "//DataBase 1.mdf"; szLine2="go\n"; szLine3='exec sp_attach_db "DataBase 2", "'+TARGETDIR + "//DataBase 2.mdf"; szLine4="go\n"; |
Note: the go are not really needed after SQL 6(?), but I put them in anyway just in case.
C. Run the batch file
If you give me a little more information, I may be able to help more.
There is great chaos under heaven, and the situation is excellent. (Mao Tse Tung)
Posted 18 October 2002 - 17:00
Hi,
what I am doing here is that running sql scripts using the below function call
if(ExecuteSQLScript(sDbname,DbName,"SQL SERVER",sUid, sPwd,Sqlfile)==0) then
MessageBox("Sql not executed",INFORMATION);
else
MessageBox("Sql executed",INFORMATION);
endif;
The function is given below
function BOOL ExecuteSQLScript(svServerName, svDatabaseName, svDriver, svUserName, svUserPassword, svScriptFile)
OBJECT pADOObj, pADOCommObj;
STRING szADOObjID, szADOCommObjID;
STRING svLine, szConnString, szSQL, svString;
NUMBER nResult,nError;
LIST listID;
begin
listID = ListCreate (STRINGLIST);
if (ListReadFromFile(listID, svScriptFile) < 0) then
MessageBox ("ERROR: Unable to open SQL script: " + svScriptFile + ".", SEVERE);
nError = 1;
return nError;
endif;
szSQL = "";
nResult = ListGetFirstString (listID, svString);
while (nResult = 0)
szSQL = szSQL + " " + svString;
nResult = ListGetNextString (listID, svString);
endwhile;
ListDestroy(listID);
szADOObjID = "ADODB.Connection";
set pADOObj = CreateObject(szADOObjID);
szConnString = "driver={" + svDriver + "};";
szConnString = szConnString + "server=" + svServerName + ";";
szConnString = szConnString + "uid=" + svUserName + ";"; szConnString = szConnString + "pwd=" + svUserPassword + ";";
szConnString = szConnString + "database=" + svDatabaseName;
pADOObj.Open(szConnString);
szADOCommObjID = "ADODB.Command";
set pADOCommObj = CreateObject(szADOCommObjID);
pADOCommObj.ActiveConnection = pADOObj;
pADOCommObj.CommandText = szSQL;
pADOCommObj.Execute();
return TRUE;
end;
But for Install scripts it is giving error.
Could you please have a look into this
Thanks,
Shajil
what I am doing here is that running sql scripts using the below function call
if(ExecuteSQLScript(sDbname,DbName,"SQL SERVER",sUid, sPwd,Sqlfile)==0) then
MessageBox("Sql not executed",INFORMATION);
else
MessageBox("Sql executed",INFORMATION);
endif;
The function is given below
function BOOL ExecuteSQLScript(svServerName, svDatabaseName, svDriver, svUserName, svUserPassword, svScriptFile)
OBJECT pADOObj, pADOCommObj;
STRING szADOObjID, szADOCommObjID;
STRING svLine, szConnString, szSQL, svString;
NUMBER nResult,nError;
LIST listID;
begin
listID = ListCreate (STRINGLIST);
if (ListReadFromFile(listID, svScriptFile) < 0) then
MessageBox ("ERROR: Unable to open SQL script: " + svScriptFile + ".", SEVERE);
nError = 1;
return nError;
endif;
szSQL = "";
nResult = ListGetFirstString (listID, svString);
while (nResult = 0)
szSQL = szSQL + " " + svString;
nResult = ListGetNextString (listID, svString);
endwhile;
ListDestroy(listID);
szADOObjID = "ADODB.Connection";
set pADOObj = CreateObject(szADOObjID);
szConnString = "driver={" + svDriver + "};";
szConnString = szConnString + "server=" + svServerName + ";";
szConnString = szConnString + "uid=" + svUserName + ";"; szConnString = szConnString + "pwd=" + svUserPassword + ";";
szConnString = szConnString + "database=" + svDatabaseName;
pADOObj.Open(szConnString);
szADOCommObjID = "ADODB.Command";
set pADOCommObj = CreateObject(szADOCommObjID);
pADOCommObj.ActiveConnection = pADOObj;
pADOCommObj.CommandText = szSQL;
pADOCommObj.Execute();
return TRUE;
end;
But for Install scripts it is giving error.
Could you please have a look into this
Thanks,
Shajil
Posted 21 October 2002 - 19:37
I assume that you're getting unhandled exception errors (which is common when working with COM objects from InstallScript). Look up the help file for "try-catch-endcatch", "exception handling" and the Err object.