Hello All,
I have a project with 2 widows that I would like to import into another project (maybe to have available for others). Is there a way to “package” these windows for easy integration into other projects? Also, these windows require (2) database tables to function. Is there a way to have this package automatically create the necessary tables?
Thanks in advance…
It might be useful to build some scripts that create your tables and any default information in a window that is only accessible through the designer.
For example:
CREATE TABLE customer
(First_Name char(50),
Last_Name char(50));
INSERT INTO customer (First_Name, Last_Name) VALUES
('John', 'Smith'),
('Gordon', 'Freeman'),
('John', 'Nash');
Make a button that runs a script that executes your SQL statements from above and stick it on a window only available through the designer. When you have a new a project import the window, switch the designer to run mode, hit the button, and you’re done.
hmmm, That got me thinking. I could create a transaction group that creates the table(s) if it doesn’t exist. I have done that previously in an older project using FSQL.
Thanks for the input.
I decided to do as suggested and have created a SQL statement to see if table exsists, and if it does not, it will be created. I have tested the script in the SQL management studio and it works fine. However, I cannot get it to run with a pushbutton event handler script.
This is the script that I have that works in the SQL management studio:
system.db.runQuery(IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TABLENAME]') AND type in (N'U')) CREATE TABLE [dbo].[TABLENAME]([Idx] [int] IDENTITY(1,1) NOT NULL,[COL1] [varchar](100) NULL,[UserID] [varchar](50) NULL,[COL2] [varchar](50) NULL,[COL3] [int] NULL,[TABLENAME_ndx] [int] NULL)
Am I missing something obvious?
Thanks
I think you should run that query in a runPrepUpdate instead of runQuery. runQuery expects a query that returns results. Try this:system.db.runPrepUpdate("IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TABLENAME]') AND type in (N'U')) CREATE TABLE [dbo].[TABLENAME]([Idx] [int] IDENTITY(1,1) NOT NULL,[COL1] [varchar](100) NULL,[UserID] [varchar](50) NULL,[COL2] [varchar](50) NULL,[COL3] [int] NULL,[TABLENAME_ndx] [int] NULL", [])
The problem has been resolved. The script is working well.
Thanks…