Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
hello,
 
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
good
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.
  Permalink  
Rate this: bad
good
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;
adapter.Fill(ds);
 
// Bind the DataSet
// ... Place your databinding code here ...
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hi
 
There is mySql connector. Using that you can connect to mySql
 
http://bitdaddys.com/MySQL-ConnectorNet.html[^]
 
issue your database creating query using the sql command
 
To check if database exists before creating use
 
CREATE DATABASE IF NOT EXIST your_database_name
 
for more reference refer
 
http://dev.mysql.com/doc/refman/5.0/en/create-database.html[^]
  Permalink  
Comments
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 OriginalGriff 469
1 ChintanShukla 305
2 Sergey Alexandrovich Kryukov 253
3 RyanDev 250
4 Richard Deeming 250
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,601
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,923


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2014
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