I normally would not ask such a question so soon with so little research, but...
I first get all grid changes into a dataset:DataSet ds = _lkpData.GetChanges();
I then loop through the dataset and build a parameter array to pass to an SQL stored procedure call, etc.
foreach (DataRow r in ds.Tables[0].Rows){ SqlParameter[] sqlParms = new SqlParameter[] { new SqlParameter("@RecordID",r.ItemArray[0]), new SqlParameter("@FinalPnL",r.ItemArray[4]), new SqlParameter("@FinalNAV",r.ItemArray[5]), new SqlParameter("@FinalReturn",r.ItemArray[6])}; My issue is referencing columns by name. The only thing I've found so far is the ItemArray collection, which works, but I need to disable the grid's column moving feature so the columns are always where I expect them to be.
I hope this is simply a matter of doing things the "hard way"?
Thanks in advance!
1. You can get a column value by name with the row indexer.
2. Column moving should have no effect on the DataRow order.
3. Consider using strongly typed dataset so you'll get a property for each row value.
Thank you Amiram. I feel embarassed because it should have been obvious to use a DataTable to GetChanges() from my strongly typed DataSet bound to the grid. I now loop through the DataTable rows referencing the columns I need by name:
DataTable dt = _lkpData.Tables["LookupData"].GetChanges();foreach (DataRow dr in dt.Rows){ SqlParameter[] sqlParms = new SqlParameter[] { new SqlParameter("@ID",dr["ItemID"]), new SqlParameter("@StartDate",dr["StartDate"])}
_mySQL.ExecuteNonQuery(...etc..., sqlParms);}
Thanks again, Jaime