Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
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 19: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 at 18-Feb-11 0:56am
Why answer a question that is almost a year old?
hari19113 at 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
0 Sergey Alexandrovich Kryukov 838
1 OriginalGriff 461
2 Tadit Dash 355
3 sanket saxena 329
4 Peter Leow 213
0 Sergey Alexandrovich Kryukov 12,109
1 OriginalGriff 7,326
2 Peter Leow 5,003
3 Abhinav S 4,003
4 Maciej Los 3,575

Advertise | Privacy | Mobile
Web01 | 2.8.140421.2 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid