Click here to Skip to main content
15,886,110 members
Articles / Database Development / MySQL

MySqlUtil - TableAdapters for MySql

Rate me:
Please Sign up or sign in to vote.
4.59/5 (7 votes)
3 Aug 20063 min read 69.2K   2.1K   47  
A program which generates Typed DataSets and TableAdapters for MySQL databases
// Copyright (c) 2006 - Rocket Computer Services Pty Ltd
// 
// This file is part of MySqlUtil.
// 
// MySqlUtil 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
// any later version.
// 
// MySqlUtil 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 Foobar; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USAusing System;

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.IO;
using System.Data;
using System.Collections.Specialized;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace MySqlDatabase
{
	/// <summary>
	/// Description of MySqlDB.
	/// </summary>
	public partial class MySqlDB
	{
		string mySqlConnectionString;
		string mySqlServer;
		string mySqlDatabaseSchema;
		string mySqlUser;
		string mySqlPassword;

		MySqlConnection mySqlConnection;
		
		bool connected = false;

		public MySqlDB()
		{
		}
		/// <summary>
		/// Connect to the MySqlServer
		/// </summary>
		/// 
		public bool Connect ( string server, string user, string password, string databaseSchema )
		{
			if ( connected )
				Close ();

			mySqlDatabaseSchema = databaseSchema;
			mySqlServer = server;
			mySqlUser = user;
			mySqlPassword = password;

			mySqlConnectionString = String.Format ( "server={0};user id={1}; password={2}; database={3}; pooling=false",
				mySqlServer, mySqlUser, mySqlPassword, mySqlDatabaseSchema );

			mySqlConnection = new MySqlConnection ( mySqlConnectionString );

			try
			{
				mySqlConnection.Open ();
			}
			catch ( MySqlException e )
			{
				MessageBox.Show ( e.Message, "MySQL Error", MessageBoxButtons.OK, MessageBoxIcon.Hand );
				return false;
			}

			connected = true;

			return true;
		}

		public void Close ()
		{
			if ( connected )
			{
				mySqlConnection.Dispose ();
				connected = false;
			}
		}

		public bool Connect ( string user, string password, string databaseSchema )
		{
			return Connect ( "", user, password, databaseSchema );
		}

		// ****************************************************************************
		// PROPERTIES
		// ****************************************************************************

		public MySqlConnection Connection
		{
			get { return mySqlConnection; }
		}

		public bool Connected
		{
			get { return connected; }
		}

		public string ConnectionString
		{
			get { return mySqlConnectionString; }
			set { mySqlConnectionString = value; }
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here



Comments and Discussions