Hi all,

I've try to execute a SWF program with ado.net. the program compile
fine, and execute fine too, but when i click on button to update or
create a new row, throw this exception:

Unhandled Exception: System.InvalidOperationException: Auto SQL
generation during Insert requires a valid SelectCommand.
in <0x0097f> System.Data.Common.DbDataAdapter:Update
(System.Data.DataRow[] dataRows, System.Data.Common.DataTableMapping
tableMapping)

i believe that's not problem with swf but there's problem with ado.net
or my code is wrong

my version of mono is:

[EMAIL PROTECTED]:~$ mono --version
Mono JIT compiler version 1.1.13.1, (C) 2002-2005 Novell, Inc and
Contributors. www.mono-project.com
        TLS:           normal
        GC:            Included Boehm (with typed GC)
        SIGSEGV      : normal

using debian unstable.

the code is attached

Cheers

Arx Cruz

--
"A fé remove montanhas, mas eu prefiro a dinamite"
// created on 19/1/2006 at 14:39
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using Npgsql;

public class ADOForm1 : Form {

	private NpgsqlDataAdapter dataAdapter;
	private DataSet dataSet;
	private DataTable dataTable;
	
	private System.ComponentModel.Container components;
	
	private System.Windows.Forms.TextBox txtNome;
	
	private System.Windows.Forms.Label lblMessage;
	
	private System.Windows.Forms.Button btnNew;
	private System.Windows.Forms.Button btnUpdate;
	private System.Windows.Forms.Button btnDelete;
	
	private System.Windows.Forms.ListBox lbCustomers;
	
	public ADOForm1() {
		
		InitializeComponent();
		
		string connectionString = "Server=192.168.1.250;User Id=admin;Password=blih;Database=acessadb";
		string commandString = "SELECT * FROM cid_cidade";
		
		dataAdapter = new NpgsqlDataAdapter(commandString, connectionString);
		
		dataSet = new DataSet();
		
		dataAdapter.Fill(dataSet, "cid_cidade");
		
		PopulateLB();
		
	}
	
	private void PopulateLB() {
		dataTable = dataSet.Tables[0];
		lbCustomers.Items.Clear();
		foreach(DataRow row in dataTable.Rows) {
			lbCustomers.Items.Add(row["cid_id"] + ": " + row["cid_cidade"]);
		}
	}
	
	
	
	private void InitializeComponent() {
		this.components = new System.ComponentModel.Container();
		
		this.txtNome = new System.Windows.Forms.TextBox();
		
		this.lblMessage = new System.Windows.Forms.Label();
		
		this.btnDelete = new System.Windows.Forms.Button();
		this.btnUpdate = new System.Windows.Forms.Button();
		this.btnNew = new System.Windows.Forms.Button();
		
		this.lbCustomers = new System.Windows.Forms.ListBox();
		
		txtNome.Location = new System.Drawing.Point(256, 300);
		txtNome.TabIndex = 4;
		txtNome.Size = new System.Drawing.Size(160, 20);
		
		lblMessage.Location = new System.Drawing.Point(32, 368);
		lblMessage.Text = "Press New, Update or Delete";
		lblMessage.Size = new System.Drawing.Size(416, 48);
		lblMessage.TabIndex = 0;
		
		btnUpdate.Location = new System.Drawing.Point(32, 300);
		btnUpdate.Size = new System.Drawing.Size(75, 23);
		btnUpdate.TabIndex = 0;
		btnUpdate.Text = "Update";
		btnUpdate.Click += new System.EventHandler(btnUpdate_Click);
		
		btnDelete.Location = new System.Drawing.Point(160, 300);
		btnDelete.Size = new System.Drawing.Size(75, 23);
		btnDelete.TabIndex = 0;
		btnDelete.Text = "Delete";
		btnDelete.Click += new System.EventHandler(btnDelete_Click);
		
		btnNew.Location = new System.Drawing.Point(472, 336);
		btnNew.Size = new System.Drawing.Size(75, 23);
		btnNew.TabIndex = 0;
		btnNew.Text = "New";
		btnNew.Click += new System.EventHandler(btnNew_Click);
		
		lbCustomers.Location = new System.Drawing.Point(32, 16);
		lbCustomers.Size = new System.Drawing.Size(368, 160);
		lbCustomers.TabIndex = 3;
		
		this.Controls.Add(txtNome);
		this.Controls.Add(lblMessage);
		this.Controls.Add(btnDelete);
		this.Controls.Add(btnNew);
		this.Controls.Add(btnUpdate);
		this.Controls.Add(lbCustomers);
		
		this.Text = "Customers Update Form";
		this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
		this.ClientSize = new System.Drawing.Size (584, 421);
	}
	
	protected void btnNew_Click(object sender, EventArgs e) {
		DataRow newRow = dataTable.NewRow();
		newRow["cid_cidade"] = txtNome.Text;
		
		dataTable.Rows.Add(newRow);
		dataAdapter.Update(dataSet, "cid_cidade");
		
		lblMessage.Text = dataAdapter.UpdateCommand.CommandText;
		
		Application.DoEvents();
		dataSet.AcceptChanges();
		
		PopulateLB();
		
		ClearFields();
	}
	
	private void ClearFields() {
		txtNome.Text = "";
	}
	
	protected void btnUpdate_Click(object sender, EventArgs e) {
		DataRow targetRow = dataTable.Rows[lbCustomers.SelectedIndex];
		lblMessage.Text = "Updating " + targetRow["cid_cidade"];
		
		Application.DoEvents();
		
		targetRow.BeginEdit();
		targetRow["cid_cidade"] = txtNome.Text;
		targetRow.EndEdit();
		
		DataSet dataSetChanged = dataSet.GetChanges(DataRowState.Modified);
		
		bool okayFlag = true;
		
		if(dataSetChanged.HasErrors) {
			okayFlag = false;
			string msg = "Error in row with customer ID ";
			
			foreach(DataTable table in dataSetChanged.Tables) {
				if(table.HasErrors) {
					DataRow[] errorRows = table.GetErrors();
					
					foreach(DataRow row in errorRows) {
						msg = msg + row["cid_id"];
					}
				}
			}
			lblMessage.Text = msg;
		}
		if(okayFlag) {
			dataSet.Merge(dataSetChanged);
			dataAdapter.Update(dataSet, "cid_cidade");
			lblMessage.Text = dataAdapter.UpdateCommand.CommandText;
			Application.DoEvents();
			dataSet.AcceptChanges();
			PopulateLB();
		} else {
			dataSet.RejectChanges();
		}
	}
	
	protected void btnDelete_Click(object sender, EventArgs e) {
		DataRow targetRow = dataTable.Rows[lbCustomers.SelectedIndex];
		string msg = targetRow["usu_nome"] + " Deleted";
		dataTable.Rows[lbCustomers.SelectedIndex].Delete();
		dataSet.AcceptChanges();
		dataAdapter.Update(dataSet, "usu_usuario");
		PopulateLB();
		lblMessage.Text = msg;
		Application.DoEvents();
	}
	
	public static void Main(string[] args) {
		Application.Run(new ADOForm1());
	}
}
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to