Click to See Complete Forum and Search --> : Create a New Database


waelsaead
June 26th, 2005, 07:31 PM
hello,

how To create a New Sql Database as Northwind when The Application Run

exterminator
June 27th, 2005, 02:40 AM
Go through any standard SQL tutorial. The queries/commands you would be using would be - "create Database" and "create table". If you are gonna use these queries regularly for maintaining your db. "drop table"/"drop database" would have to be included as needed. Now run the script that you make in the SQL Query Analyzer (or any SQL editor that relates to your database)

In this case as you wish to create a db by the name - Northwind then beware since I guess there is a northwind database that comes with the SQL server. If its there ..take care you dont remove it and make your own over it. In case you dont need the existing one, you can for sure go ahead.

A sample simple tutorial could be found at:
http://www.w3schools.com/sql/sql_create.asp

All the best...Cheers,
Exterminator

waelsaead
June 27th, 2005, 09:35 AM
Thanks For reply..

But I know How to create Sql database With
Sql Enterprise Manger it's Very Easy... I mean how To create Database By write a Csharp Code

exterminator
June 27th, 2005, 10:02 AM
Creating it from your code is also very easy!!!
You created the SQL statements - now you just need to execute them.
Here are the steps:

1. Create the connection string.
2. Build the SQL string - your SQL statement for creating database or tables etc.
3. Open the Connection.
4. Create an SQL Command Object.
5. With the SQL Command Object call the ExecuteNonQuery() Method.

Simple ..isnt it? For a sample, go through this link :
http://www.c-sharpcorner.com/Code/2002/Mar/CreatingDBProgrammaticallyMCB.asp

However, dont just copy the functions. There are a few issues there. One that I found was the author creates a connection in the "CreateDBBtn_Click" event and then calls the method "ExecuteSQLStmt" and there he closes the existing connection and re-open one. This is just an overhead. You just need to do it once. But the whole article gets you through with the concept.

[Don't forget to rate if this is of any help to you!]
Cheers,
Exterminator.

waelsaead
June 27th, 2005, 03:12 PM
very very thanks