Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ctrl+S is DataGrid does not save data
Message
From
01/01/2007 20:14:18
 
 
To
01/01/2007 18:54:06
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 1.1
Miscellaneous
Thread ID:
01181178
Message ID:
01181259
Views:
12
> I put a breakpoint in my grid sub-class and checked the value of
>in the ImmediateWindow both before and after the .Refresh(). It was the old value before the refresh and the new value after the refresh. If you haven't tried this, try it first

Thank you for the tip. I have DataTable bound to DataGrid and Datamember is not set. I checked

((DataTable)DataSource).Rows[this.CurrentCell.RowNumber][this.CurrentCell.ColumnNumber]

and this value changes properly: after refresh it contains new vale.

I use the following method to save data.
In this method Update() returns 0 and value is not updated in database.
public static int Save(DataSet ds, string tableName,
		string primaryKeyName, bool retrieveAutoIncrementPK,
							IDbDataAdapter dbAdapter)
		{
			DataSet changes = ds.GetChanges();
			NpgsqlTransaction transact = Connection.BeginTransaction();
			int RowsUpdated = 0;
			if (changes != null)
			{
				if (retrieveAutoIncrementPK)
					((NpgsqlDataAdapter)dbAdapter).RowUpdated +=
						delegate(object sender, NpgsqlRowUpdatedEventArgs args)
						{
							if (args.StatementType == StatementType.Insert)
							{
								if (args.Row[primaryKeyName].ToString() == "")
									args.Row[primaryKeyName] = SequenceCurrentValue(
										args.Row.Table.TableName, primaryKeyName);
							}
						};

				try
				{
					RowsUpdated = dbAdapter.Update(changes);
				}
				catch (NpgsqlException e)
				{
					transact.Rollback();
					throw e;
				}
			}

			transact.Commit();
			if (changes != null)
				ds.Merge(changes, false, MissingSchemaAction.Error);

			ds.AcceptChanges();
			foreach (DataRow dr in ds.Tables[tableName].Rows)
				if (dr[dr.Table.PrimaryKey[0].ColumnName].GetType() ==
						typeof(System.DBNull))
					dr.Delete();

			ds.AcceptChanges();

			return RowsUpdated;
		}
> ... it may be something else that's causing it to not work, but off the top of my head I have no ideas.
I think this must be something simple since this is my first C# application.

How I can debug this issue?
I have my .NET data provider (npgsql) source code but its study is a lot of work.
Which is easiest way to solve this issue?


> How *are* you setting the grid's DataSource BTW?

I use the following code to build grid
foreach (GridColumnDataSet.GridColumnsRow
		dr in dataGridColumns.GridColumns) {
string columnName = dr.controlsrc.Trim();
DataGridColumnStyle colStyle;

if (table.Columns[columnName].DataType.Name == "Boolean") { 
	colStyle = new DataGridBoolColumn();
	((DataGridBoolColumn)colStyle).AllowNull = false;
	}
else {
	colStyle = new DataGridTextBoxColumn();
	if (table.Columns[columnName].DataType.Name == "Decimal")
		colStyle.Alignment = HorizontalAlignment.Right;
}
colStyle.MappingName = dr.controlsrc.Trim();
colStyle.HeaderText = dr.veerunimi.Trim();
colStyle.Width = dr.width;
tableStyle.GridColumnStyles.Add(colStyle);
}
TableStyles.Add(tableStyle);
DataSource = table;
> (and ... are we talking about DataGrid or the new DataGridView? I tried this with the old DataGrid).

I used DataGrid too.
I havent tried DataGridView.
Andrus
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform