Click here to Skip to main content
16,006,441 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,

As I said in a previous post, I am learning VB.net and I like it very much.

Now I have arrived at the database part. In all books I have and all tutorials I found all the examples of making a database are explained creating database from
Visual Studio. The problem is, I would like my application when it runs for the first time to create a new and empty database file with all Fields and Keys.

How I did during the design. Now I am looking for to make a simple database with fields like:

Name as string, Country as String, codes as string or Array.

So can some help me to find the solution? Can you please send the code?

Also I saw that it could be possible using vb.net code and/or MySql. It would be very interesting to see the difference.

Please help Me
Jorkax

Moved from answer:
Hi everybody,
can someone help me?
I need to study the code in vb.net to create a simple local database.
I am sorry if I did not understand previuos examples.
what I need?
1 - a simple connection strings ( maybe I can use the visual studio wizzard )
2 - Vb.net code ( not using MySql ) to create local database ( even the file *.mdf )
3 - how to create a table a differnt kind of fields
I found many examples on line but not as clear as I look for ( http://www.vb-helper.com/howto_net_runtime_dataset.html )
please help me
you may contact me even personally
I can recognize your help
Thank you
Posted
Updated 28-Jan-11 0:49am
v3
Comments
Manfred Rudolf Bihy 28-Jan-11 6:50am    
Moved OP's answer into the question.

Most databases come with clients that will generate the required SQL for you, which will crate the tables, views, stored procs etc. On first run, you basically need to execute this auto generated SQL on the target database server.

It's also possible to include actual table data in the SQL (if you wish to input some initial data).

Alternatively, you can create a backup of the default DB and restore it during installation (on the target machine). Different databases call this by different terms though, SQL server uses backup/restore. MySQL may use similar terminology (google it out).
 
Share this answer
 
v2
You mentioned MySql, but didn't say it was a requirement...so I thougth I'd point out this Tip/Trick that has several methods for creating an access/Jet database file:

Create a blank Jet database[^]

But in general what you are asking should be possible in virtually any language and with a variety of different types of databases. Once you get the blank database you just need the proper SQL to build the files...for example, this would build a table like what you are asking in an access db:
CREATE TABLE myTable(
  Name TEXT (80) NOT NULL DEFAULT='', 
  Country TEXT (80) NOT NULL DEFAULT='',
  Codes  TEXT (20) NOT NULL DEFAULT=''
);

You should research the SQL Create Table Statement[^].
 
Share this answer
 
Hey guys!

Ofcourse this is possible, I would however recommend you track your changes using SQL Scripts. Those scripts contain all changes you've made in your development environment. If you run those scripts, your database will be reproduced, which sounds like exactly what you want.

To create a new database, and run the scripts, you may want to use SQL Server Management Objects (SMO)

ServerConnection serverConnection = new ServerConnection();
serverConnection.ConnectionString = ConnectionString;
serverConnection.Connect();

Microsoft.SqlServer.Management.Smo.Server sqlServer = new Microsoft.SqlServer.Management.Smo.Server(serverConnection);
                
Database createdDatabase = new Database();
createdDatabase.Name = DatabaseName;
createdDatabase.Parent = sqlServer;
createdDatabase.Create();
databaseCreated = true;

serverConnection.Disconnect();


Good luck!
 
Share this answer
 
Comments
anu.99 28-Feb-12 12:17pm    
i want to connect with sqlserver without installing sql server

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900