[Mono-list] [PATCH] DataRow.cs

Carlos Guzmán Álvarez carlosga@telefonica.net
Tue, 19 Nov 2002 20:40:12 +0100


Hello:

I´m having problems trying to make this:

schemaRow["BaseSchemaName"] = null;

SchemaRow is a Datarow instance and BaseSchemaName is defined as:

schema.Columns.Add("BaseSchemaName",System.Type.GetType("System.String"));

This works well on csc but not on mcs.



Here is the patch for this:

DataRow.cs

The change affects to the indexer:

	public object this[DataColumn column]

Add this to line 99 (before bool objIsDBNull = value.Equals(DBNull.Value);):


value = (value == null) ? DBNull.value : value;



Here is the indexer changed:

public object this[DataColumn column] {
	[MonoTODO] //FIXME: will return different values depending on DataRowState
	get { return this[column, DataRowVersion.Current]; }
						
	[MonoTODO]
	set {
		// The new line
		value = (value == null) ? DBNull.value : value;		
		bool objIsDBNull = value.Equals(DBNull.Value);
		if (column == null)
			throw new ArgumentNullException ();
		int columnIndex = _table.Columns.IndexOf (column);
		if (columnIndex == -1)
			throw new ArgumentException ();
		if(column.DataType != value.GetType ()) {
			if(objIsDBNull == true && column.AllowDBNull == false)
				throw new InvalidCastException ();
			//else if(objIsDBNull == false)
			//	throw new InvalidCastException ();
		}

		if (rowState == DataRowState.Deleted)
			throw new DeletedRowInaccessibleException ();

		//MS Implementation doesn't seem to create the proposed or original
		//set of values when a datarow has just been created or added to the
		//DataTable and AcceptChanges() has not been called yet.

		if(rowState == DataRowState.Detached || rowState == DataRowState.Added) {
			if(objIsDBNull)
				current[columnIndex] = DBNull.Value;
			else
				current[columnIndex] = value;
		}
		else {
			BeginEdit ();  // implicitly called

			rowState = DataRowState.Modified;

			if(objIsDBNull)
				proposed[columnIndex] = DBNull.Value;
			else
				proposed[columnIndex] = value;
		}

		//Don't know if this is the rigth thing to do,
		//but it fixes my test. I believe the MS docs only say this
		//method is implicitly called when calling AcceptChanges()

		// EndEdit (); // is this the right thing to do?

	}
}





Best regards
Carlos Guzmán Álvarez
Vigo - Spain