Martin Paul Eve bio photo

Martin Paul Eve

Professor of Literature, Technology and Publishing at Birkbeck, University of London

Email Books Twitter Github Stackoverflow MLA CORE Institutional Repo ORCID ID  ORCID iD Wikipedia Pictures for Re-Use

Just been asked some further questions about the DataExecutor class on FreeNode and thought I'd give some usage instructions/clarification here.

Howto: Fill a strongly typed dataset

Set your base class (of your TableAdapter) to Tools.genericTableAdapter.

Fill your strongly typed DataSet thus:

DataExecutor de = null;

		de = new DataExecutor();
		const string TABLEPREFIX = "blog";
		MySqlCommand cmd = new MySqlCommand(string.Format("SELECT * FROM {0} WHERE id=@id", TABLEPREFIX));
		cmd.Parameters.AddWithValue("@id", id);
		de.NextCommand(cmd, false);

		DataSchema.blog_postsDataTable postsDT = new DataSchema.blog_postsDataTable();

		DataTable dtRef = (DataTable)postsDT;

		de.DataSetSchema(ref dtRef);
	} finally {
		if(de != null) de.Close();

Why do it like this?

Answer: because it lets you hook into the return results for testing purposes.

de = new Tools.DataExecutor(true);
de.OnTestModeFill += new Tools.DataExecutor.TestModeFillInterceptor(taskFillHandler);

Then in taskFillHandler you will receive a reference to a DataTable that you can populate in whatever way you like to ensure that your application behaves correctly - aka. offline database unit testing!