[Mono-dev] Adding data to a dataset question

Paul F. Johnson paul at all-the-johnsons.co.uk
Wed Aug 10 08:03:18 EDT 2005


I'm trying to add multiple lines to a dataset but keep hitting the same
problem. Now, I can get around the problem, but I'm not happy with how I have
to do it.

The code looks like this

		private void FillDataSet()
			// create a new DataTable in the DataSet
			dsSource.Tables["sites"].Columns.Add("url", Type.GetType("System.String"));
			// create a few rows and add them to the DataTable
			DataRow tempRow = dsSource.Tables["sites"].NewRow();
			tempRow["url"] = "http://www.gotmono.com";
			tempRow["name"] = "Mono community page";
			tempRow["url"] = "http://www.go-mono.com/tutorial";
			tempRow["name"] = "The Mono handbook";
			tempRow["url"] = "http://www.go-mono.com";
			tempRow["name"] = "The main Mono website";
		        tempRow["url"] =
			tempRow["name"] = "Mono WineSamples";
		private void BindControls()
			// Bind the listBox
			listBox1.DataSource = dsSource.Tables["sites"];
			listBox1.DisplayMember = "name";
			listBox1.ValueMember = "url";
			// Bind the combobox
			comboBox1.DataSource = dsSource.Tables["sites"];
			comboBox1.DisplayMember = "name";
			comboBox1.ValueMember = "url";
			// Bind the DataGrid to the DataSet
			dataGrid.DataSource = dsSource;
			// Bind the second DataGrid to the DataSet
			dataGrid2.DataSource = dsSource.Tables["sites"];
			// Bind the Textboxes to the selected row
			textBox.DataBindings.Add("text", dsSource.Tables["sites"], "name");
			textBox2.DataBindings.Add("text", dsSource.Tables["sites"], "url");

Clearly, the problem is coming from using temp constantly in the setting of
the data (if I comment out all but the first dataadd set, the program works
correctly-ish). The solution looks to be use an array of temps to add the

If the dataset type was an int, I could say ds.AutoIncrement (according to

Is there a way to reuse temp or is the problem in that when the data is added,
the row counter is not incremented and so I'm trying to overwrite the same
data time and again?


"Logic, my dear Zoe, is merely the ability to be wrong with authority" - Dr

More information about the Mono-devel-list mailing list