MyCodeGenCS: C# Code Generator for MySQL

project details downloads


MyCodeGenCS is a free C# code generating tool for MySQL. This tool reads your MySQL databases, lists tables and generates codes. Tables in your database become usable classes, and you don't even have to modify any generated sources, but just use them easily. And the useage is really simple.

This software used MySQLDriverCS as MySQL driver.

INSTALLATION


Just run bin\mycodegencs.exe.

 

REQUIREMENTS


OS: Win2000/WinXP/Win2003
Microsoft .NET Framework 1.1
MySQL

USAGE


1 Put your MySQL login info on the top, then press "Connect" button. Your databases of MySQL on your computer will show up on the left side listbox.
2 Double click on any database you want to generate your code on the listbox, tables of the database will be listed.
3 Check which tables you want to generate, you can use "Select All" or "Select None" button.
4 By default, source code will be generated in C:\My Generated Projects\[Database name] you can modify this at any time.
5 Change the namespace you want the code to be in, by default, the namespace will be [Database name].Db
6 Press "Generate Code" button. When it finishes, the generated folder will show up.
7 Your MySQL login info will be put into the Db\db.cs, open that file, find the line:
protected string strMySqlConn = "Data Source=[table];Password=[password];User ID=[username];Location=[location]";
you may want to change this if you want your code be used for other MySQL databases. Otherwise, you don't have to modify this.
8 This generator also generates .csproj and .sln file. You can use them directly, try to open them and compile your new generated project. Or you can put the Db folder and files in bin\Debug in any of your projects for use when you changed the namespace.

Sorry I've not translated the comments in db.cs.

EXAMPLE


Example:

if we have this table called `test' in the MySQL database:

------------------------------------------------------------

Field Type Key Extra
mid
int(11) Primary Key auto_increment
name varchar(50)    
phone varchar(50)    

------------------------------------------------------------

it will generate this code:
look at the Gettest(int mid) function, the mid is the primary key of the table.

------------------------Code begins-------------------------

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using MySQLDriverCS;

namespace codegen.Db
  {
  public class test
    {
    private int m_mid;
    private string m_name;
    private string m_phone;
    public test(){}
    public virtual int mid
      {
      get
        {
        return this.m_mid;
        }
      set
        {
        this.m_mid = value;
        }
      }
    public virtual string name
      {
      get
        {
        return this.m_name;
        }
      set
        {
        this.m_name = value;
        }
      }
    public virtual string phone
      {
      get
        {
        return this.m_phone;
        }
      set
        {
        this.m_phone = value;
        }
      }
    public virtual bool Gettest(int mid)
      {
      try
        {
        MySqldb mydb = new MySqldb();
        ;
        MySQLDataReader myreader;
        myreader = mydb.ExecSqlReader("select * from test where mid='" + mid + "';");
        do
          {
          this.m_mid = int.Parse(myreader["mid"].ToString());
          this.m_name = myreader["name"].ToString();
          this.m_phone = myreader["phone"].ToString();
          }

        while (myreader.Read());
        return true;
        }
      catch (System.Exception)
        {
        return false;
        }
      finally{
      }
      }
    }
  }
-------------------Code Ends ------------------

COPYRIGHT


MyCodeGenCS is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

MyCodeGenCS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with MySQLDriverCS; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

RELEASE VERSION 1.0 NOTES


Date: 2-12, 2005

Features:
- Lists all databases
- Lists all tables
- Generates .sln and .csproj
- Added a method Get[tablename](key)
- Works for different types of MySQL.


© 2005 MyCodeGenCS Project

SourceForge.net Logo