jenniferw
asked on
Problems with DataAdapter.Update ( )
When I push the Edit DataGrid button above the DataGrid, I get a DataGrid where every row and cell are
in EditMode.
But when I push the Update DataGrid button above the dataGrid, only the first row in the dataset is
updated in the database, and then a a System.FormatExeption, saying: "Index (zero based) must be greater
than or equal to zero and less than the size of the argument list." is thrown.
My button update code is as follows:
public void UpdateDataGrid_Click(objec t sender, System.EventArgs e)
{
try
{
DataRowCollection dr;
DataTable dt = dsProductParameter.Product Parameter;
dr = dt.Rows;
for (int i = 0; i < ProductParameterGrid.Items .Count; i++)
{
// Copy values from datagrid
dr[i]["ID"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 2].Control s[3]).Text ;
dr[i]["Name"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 3].Control s[3]).Text ;
dr[i]["Description"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 4].Control s[3]).Text ;
dr[i]["PropertyValue"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 5].Control s[3]).Text ;
dr[i]["PropertyValueDataTy pe"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 6].Control s[3]).Text ;
dr[i]["PropertyValueUnitOf Measure"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 7].Control s[3]).Text ;
}
dbcInterface.UpdateProduct Parameter( dsProductP arameter);
..........
}
My UpdateProductParameter( ) method code that fails is :
public void UpdateProductParameter(DSP roductPara meter ds)
{
try
{
sqlDaProductParameter.Upda te(ds);
}
catch (System.Exception Se)
{
.......
}
}
What am I doing wrong?
in EditMode.
But when I push the Update DataGrid button above the dataGrid, only the first row in the dataset is
updated in the database, and then a a System.FormatExeption, saying: "Index (zero based) must be greater
than or equal to zero and less than the size of the argument list." is thrown.
My button update code is as follows:
public void UpdateDataGrid_Click(objec
{
try
{
DataRowCollection dr;
DataTable dt = dsProductParameter.Product
dr = dt.Rows;
for (int i = 0; i < ProductParameterGrid.Items
{
// Copy values from datagrid
dr[i]["ID"] = ((TextBox)ProductParameter
dr[i]["Name"] = ((TextBox)ProductParameter
dr[i]["Description"] = ((TextBox)ProductParameter
dr[i]["PropertyValue"] = ((TextBox)ProductParameter
dr[i]["PropertyValueDataTy
dr[i]["PropertyValueUnitOf
}
dbcInterface.UpdateProduct
..........
}
My UpdateProductParameter( ) method code that fails is :
public void UpdateProductParameter(DSP
{
try
{
sqlDaProductParameter.Upda
}
catch (System.Exception Se)
{
.......
}
}
What am I doing wrong?
ASKER
Yes.
Have you combined multiple modifications, deletes, updates into one update?
Bob
Bob
ASKER
No, I'm just editing the cells in the datagrid, and calling update.
No deletes.
No deletes.
ASKER
And no inserts....
This is just a test:
DataRow[] rows = new DataRow[dt.Rows.Count];
dt.Rows.CopyTo(rows, 0);
dbcInterface.UpdateProduct Parameter( rows);
Does that work?
Bob
DataRow[] rows = new DataRow[dt.Rows.Count];
dt.Rows.CopyTo(rows, 0);
dbcInterface.UpdateProduct
Does that work?
Bob
ASKER
I don't have access to the web server, so I'm not able to test it today...
But, why don't it work with a DataSet? What is making the index in the DataSet?
And what is the index in the DataRow[] rows.
But, why don't it work with a DataSet? What is making the index in the DataSet?
And what is the index in the DataRow[] rows.
ASKER
My primary key, ProductParameterGlobalID, the row identifier contains numbers
greater than the size of the argument list. Could that be the problem?
greater than the size of the argument list. Could that be the problem?
It shouldn't matter what the values for the primary key column, since it is an argument index out-of-range exception that you are getting.
Bob
Bob
ASKER
I have tested:
DataRow[] rows = new DataRow[dt.Rows.Count];
dt.Rows.CopyTo(rows, 0);
dbcInterface.UpdateProduct Parameter( rows);
It doesn't solve the problem...
Jennifer
DataRow[] rows = new DataRow[dt.Rows.Count];
dt.Rows.CopyTo(rows, 0);
dbcInterface.UpdateProduct
It doesn't solve the problem...
Jennifer
What does the UpdateCommand.CommandText look like for sqlDaProductParameter?
Bob
Bob
ASKER
Here it comes.....
UPDATE [ProductParameter] SET [ProductSegmentGlobalId] = @ProductSegmentGlobalId, [ID] = @ID, [Name] = @Name, [Description] = @Description, [PropertyValue] = @PropertyValue, [PropertyValueDataType] = @PropertyValueDataType, [PropertyValueUnitOfMeasur e] = @PropertyValueUnitOfMeasur e, [LastModified] = @LastModified WHERE (([ProductParameterGlobalI d] = @Original_ProductParameter GlobalId) AND ([ProductSegmentGlobalId] = @Original_ProductSegmentGl obalId) AND ([ID] = @Original_ID) AND ((@IsNull_Name = 1 AND [Name] IS NULL) OR ([Name] = @Original_Name)) AND ((@IsNull_Description = 1 AND [Description] IS NULL) OR ([Description] = @Original_Description)) AND ((@IsNull_PropertyValue = 1 AND [PropertyValue] IS NULL) OR ([PropertyValue] = @Original_PropertyValue)) AND ((@IsNull_PropertyValueDat aType = 1 AND [PropertyValueDataType] IS NULL) OR ([PropertyValueDataType] = @Original_PropertyValueDat aType)) AND ((@IsNull_PropertyValueUni tOfMeasure = 1 AND [PropertyValueUnitOfMeasur e] IS NULL) OR ([PropertyValueUnitOfMeasu re] = @Original_PropertyValueUni tOfMeasure )) AND ([LastModified] = @Original_LastModified));
SELECT ProductParameterGlobalId, ProductSegmentGlobalId, ID, Name, Description, PropertyValue, PropertyValueDataType, PropertyValueUnitOfMeasure , LastModified FROM ProductParameter WHERE (ProductParameterGlobalId = @ProductParameterGlobalId) ORDER BY ProductParameterGlobalId
Jennifer
UPDATE [ProductParameter] SET [ProductSegmentGlobalId] = @ProductSegmentGlobalId, [ID] = @ID, [Name] = @Name, [Description] = @Description, [PropertyValue] = @PropertyValue, [PropertyValueDataType] = @PropertyValueDataType, [PropertyValueUnitOfMeasur
SELECT ProductParameterGlobalId, ProductSegmentGlobalId, ID, Name, Description, PropertyValue, PropertyValueDataType, PropertyValueUnitOfMeasure
Jennifer
Pretty straight-forward stuff. I can't see any explanation for your problem. Are you maybe exceeding the max length for a string column?
Bob
Bob
ASKER
No...
But I'm using a dataView upon the dataset, perhaps there is a problem with that?
Jennifer
But I'm using a dataView upon the dataset, perhaps there is a problem with that?
Jennifer
Are you using the DataView to filter and sort?
Bob
Bob
ASKER
Yes...Hmmm...
Are you thinking, scratching your head, pondering options, what?
Bob
Bob
ASKER
Yes....
Ok, when you're done and you want to share some information with me, just let me know ;)
Bob
Bob
ASKER
Well, then I'm back.
Now it's working, but i don't fully understand why.
Have a look at this code:
public void UpdateDataGrid_Click(objec t sender, System.EventArgs e)
{
try
{
DataRowCollection ds = dsProductParameter.Product Parameter. Rows;
DataRowCollection dv = dataViewProductParameter.T oTable().R ows;
for (int i = 0; i < ds.Count; i++)
{
for (int j = 0; j < dv.Count; j++)
{
if (dv[i]["ProductParameterGl obalID"] == ds[j]["ProductParameterGlo balID"])
{
// Copy values from datagrid to dataset
ds[j]["ID"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 2].Control s[3]).Text ;
ds[j]["Name"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 3].Control s[3]).Text ;
ds[j]["Description"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 4].Control s[3]).Text ;
ds[j]["PropertyValue"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 5].Control s[3]).Text ;
ds[j]["PropertyValueDataTy pe"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 6].Control s[3]).Text ;
ds[j]["PropertyValueUnitOf Measure"] = ((TextBox)ProductParameter Grid.Items [i].Cells[ 7].Control s[3]).Text ;
}
}
dbcInterface.UpdateProduct Parameter( dsProductP arameter);
}
................etc....... .......... ........
First I take care of the view/set sorting problem.
Than I'm running the update method for every loop.
I don't fully understand why I have to do that, perhaps you could help?
I wanted to fill the dataSet with new information and call the update method once.
But the FormatException is thrown....
Now it's working, but i don't fully understand why.
Have a look at this code:
public void UpdateDataGrid_Click(objec
{
try
{
DataRowCollection ds = dsProductParameter.Product
DataRowCollection dv = dataViewProductParameter.T
for (int i = 0; i < ds.Count; i++)
{
for (int j = 0; j < dv.Count; j++)
{
if (dv[i]["ProductParameterGl
{
// Copy values from datagrid to dataset
ds[j]["ID"] = ((TextBox)ProductParameter
ds[j]["Name"] = ((TextBox)ProductParameter
ds[j]["Description"] = ((TextBox)ProductParameter
ds[j]["PropertyValue"] = ((TextBox)ProductParameter
ds[j]["PropertyValueDataTy
ds[j]["PropertyValueUnitOf
}
}
dbcInterface.UpdateProduct
}
................etc.......
First I take care of the view/set sorting problem.
Than I'm running the update method for every loop.
I don't fully understand why I have to do that, perhaps you could help?
I wanted to fill the dataSet with new information and call the update method once.
But the FormatException is thrown....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank's for helping...
Bob