Click here to Skip to main content
15,896,154 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.4K   2.1K   47  
A program which generates Typed DataSets and TableAdapters for MySQL databases
/*
 * Created by SharpDevelop.
 * User: Ian Semmel
 * Date: 11/07/2006
 * Time: 4:59 AM
 */

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