Click here to Skip to main content
13,345,867 members (52,578 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I want to create a mysql database (contains 1 table) if it not exists in the server by using a csharp application, please help
Posted 11-Mar-10 20:25pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The obvious way to do this is to simply make an empty DB a resource in your app and write it out to the file system. Executing scripts to create a DB and a table are, however, also trivial tasks.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You will need to download and install the MySQL Connector/Net ADO.NET library. Once you’ve added the MySql.Data.dll assembly as a reference to your project or placed it in your /bin folder, you are ready to start writing code to access MySQL. Here is an example of connecting to MySQL and retrieving all of the rows from the verse table into a DataSet.
// Connection string for a typical local MySQL installation
string cnnString = "Server=localhost;Port=3306;Database=versedb;Uid=root;Pwd=MySecretPassword";

// Create a connection object and data adapter
MySqlConnection con = new MySqlConnection(cnnString);
MySqlDataAdapter adapter = new MySqlDataAdapter();

// Create a SQL command object
MySqlCommand cmd = new MySqlCommand("SELECT * FROM product", con);

// Create a fill a Dataset
DataSet ds = new DataSet();
adapter.SelectCommand = cmd;

// Bind the DataSet
// ... Place your databinding code here ...
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

There is mySql connector. Using that you can connect to mySql[^]

issue your database creating query using the sql command

To check if database exists before creating use


for more reference refer[^]
JF2015 18-Feb-11 0:56am
Why answer a question that is almost a year old?
hari19113 7-Jul-12 23:31pm
hope he has got the answer...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100