building an SQLServer database
I need to know how to connect to data in a database I create incode, in SQLServer. Does anyone know what I need in order to set the connection in runtime with the new database name?
(I didn't mean to post duplicate threads, it happend because I sent my post when I weren't near the computer about mor then 15 minutes, and then you get the chance to write your user and passward again - what made me think my thread wasn't there. I didn't know it was there already.)
Re: change name of connection to SQLServer on runtime
To connect to any SQL Server database you need to assign the appropriate values to the ConnectionString property of an SqlConnection object. www.connectionstrings.com has the appropriate formats. If you want to build a connection string piece by then, assuming that you're using VB 2005, the easiest way is with an SqlConnectionStringBuilder.
Re: building an SQLServer database
I did that before I even read your reply, and it works, thanks.
Now I'm searching for a way to build relations between tables, this time in SQLServer. I've googled and so far had no luck.
Re: building an SQLServer database
You create relations when you create the child table by specifying a constraint.
http://msdn2.microsoft.com/en-us/library/ms174979.aspx
I'd assume you can do an ALTER TABLE too after the fact but I've never done so.
Re: building an SQLServer database
Thank you very much, I think this is what I'm looking for.
:)
Re: building an SQLServer database
Look, I've tried using your link, and here's my query after trying:
CREATE TABLE tbl_A({A_ID NUMBER CONSTRAINT fk_tbIA_tbIE_id (FOREIGN
KEY REFERENCES tbl_E(E_ID) ON DELETE CASCADE ON UPDATE CASCADE), name char(1)} )
CREATE TABLE tbl_E( { E_ID NUMBER, name char(1) } )
It haas syntax errors. can you see them? I bet it refers to the parentheses.
Re: building an SQLServer database
You must create TBLE first - right?
Also - get into Management Studio and put in that DDL statement - it will help you see you syntax errors better.
Why are you creating a table from code?