Click here to Skip to main content
15,881,852 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.1K   2.1K   47  
A program which generates Typed DataSets and TableAdapters for MySQL databases
namespace MyqfrsDataSet_namespace
{
	public partial class FireserviceDataTable
	{
		MySqlConnection connection;
		bool connected;
		MySqlDataAdapter adapter;
		MySqlCommand deleteCommand;
		MySqlCommand insertCommand;
		MySqlCommand updateCommand;

		public bool Connect ()
		{
			connection = dataSet.NewConnection ();
			if ( connection == null )
				return false;
			InitAdapter ();
			connected = true;
			return true;
		}

		public override System.Data.DataTable Clone ()
		{
			FireserviceDataTable cln = ( (FireserviceDataTable) ( base.Clone () ) );
			cln.columnFireServiceID = base.Columns [ "FireServiceID" ];
			cln.columnName = base.Columns [ "Name" ];
			cln.columnAddress_1 = base.Columns [ "Address_1" ];
			cln.columnAddress_2 = base.Columns [ "Address_2" ];
			cln.columnTown = base.Columns [ "Town" ];
			cln.columnState = base.Columns [ "State" ];
			cln.columnPostCode = base.Columns [ "PostCode" ];
			cln.columnCommissioner = base.Columns [ "Commissioner" ];
			cln.columnPhone = base.Columns [ "Phone" ];
			return cln;
		}

		void InitAdapter ()
		{
			adapter = new MySqlDataAdapter ( "SELECT * FROM fireservice", connection );

			using ( MySqlCommandBuilder builder = new MySqlCommandBuilder ( adapter ) )
			{
				deleteCommand = builder.GetDeleteCommand ();
				insertCommand = builder.GetInsertCommand ();
				updateCommand = builder.GetUpdateCommand ();
			}

            insertCommand.Parameters [ "FireServiceID" ].Value = 0;
			insertCommand.Parameters [ "FireServiceID" ].Direction = ParameterDirection.InputOutput;
            insertCommand.Parameters [ "Name" ].Value = "QFRS";
            insertCommand.Parameters [ "Address_1" ].Value = "First Floor";
            insertCommand.Parameters [ "Address_2" ].Value = "123 Smith Street";
            insertCommand.Parameters [ "Town" ].Value = "Brisbane";
            insertCommand.Parameters [ "State" ].Value = "Queensland";
            insertCommand.Parameters [ "PostCode" ].Value = "4000";
            insertCommand.Parameters [ "Commissioner" ].Value = "Fred Nerk";
            insertCommand.Parameters [ "Phone" ].Value = "1111-1111";

			insertCommand.Connection = connection;

			object rc = insertCommand.ExecuteScalar ();

			object v = insertCommand.Parameters [ "FireServiceID" ].Value;

			FireserviceRecord rec = new FireserviceRecord ();

			rec.commissioner = "ADDED";

			this.AddFireserviceRow ( rec );

			DataTable tab = this.GetChanges ();

			if ( tab != null )
			{
				adapter.InsertCommand = null;
				adapter.Update ( tab );
			}
		}
	}
}

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