[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problems with DataAdapter.Update ( )

Posted on 2006-04-06
22
Medium Priority
?
267 Views
Last Modified: 2008-03-10
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(object sender, System.EventArgs e)
{
            try
            {
                DataRowCollection dr;
                DataTable dt = dsProductParameter.ProductParameter;
                dr = dt.Rows;

                for (int i = 0; i < ProductParameterGrid.Items.Count; i++)
                {
                    // Copy values from datagrid
                    dr[i]["ID"] = ((TextBox)ProductParameterGrid.Items[i].Cells[2].Controls[3]).Text;
                    dr[i]["Name"] = ((TextBox)ProductParameterGrid.Items[i].Cells[3].Controls[3]).Text;
                    dr[i]["Description"] = ((TextBox)ProductParameterGrid.Items[i].Cells[4].Controls[3]).Text;
                    dr[i]["PropertyValue"] = ((TextBox)ProductParameterGrid.Items[i].Cells[5].Controls[3]).Text;
                    dr[i]["PropertyValueDataType"] = ((TextBox)ProductParameterGrid.Items[i].Cells[6].Controls[3]).Text;
                    dr[i]["PropertyValueUnitOfMeasure"] = ((TextBox)ProductParameterGrid.Items[i].Cells[7].Controls[3]).Text;
                }

                    dbcInterface.UpdateProductParameter(dsProductParameter);

                     ..........
}

My UpdateProductParameter( ) method code that fails is :

public void UpdateProductParameter(DSProductParameter ds)
{
     try
     {
           sqlDaProductParameter.Update(ds);
     }
     catch (System.Exception Se)
     {
                      .......
                }
}

What am I doing wrong?
0
Comment
Question by:jenniferw
  • 12
  • 10
22 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16393536
Does ProductParameterGrid.Items.Count = dsProductParameter.ProductParameter.Rows.Count?

Bob
0
 

Author Comment

by:jenniferw
ID: 16393687
Yes.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16393705
Have you combined multiple modifications, deletes, updates into one update?

Bob
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jenniferw
ID: 16393724
No, I'm just editing the cells in the datagrid, and calling update.
No deletes.
0
 

Author Comment

by:jenniferw
ID: 16393950
And no inserts....
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16393951
This is just a test:

  DataRow[] rows = new DataRow[dt.Rows.Count];
  dt.Rows.CopyTo(rows, 0);

  dbcInterface.UpdateProductParameter(rows);

Does that work?

Bob
0
 

Author Comment

by:jenniferw
ID: 16394083
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.
0
 

Author Comment

by:jenniferw
ID: 16394402
My primary key, ProductParameterGlobalID, the row identifier contains numbers
greater than the size of the argument list. Could that be the problem?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16394720
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
0
 

Author Comment

by:jenniferw
ID: 16398371
I have tested:

  DataRow[] rows = new DataRow[dt.Rows.Count];
  dt.Rows.CopyTo(rows, 0);

  dbcInterface.UpdateProductParameter(rows);

It doesn't solve the problem...

Jennifer
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16399710
What does the UpdateCommand.CommandText look like for sqlDaProductParameter?

Bob
0
 

Author Comment

by:jenniferw
ID: 16399845
Here it comes.....

UPDATE [ProductParameter] SET [ProductSegmentGlobalId] = @ProductSegmentGlobalId, [ID] = @ID, [Name] = @Name, [Description] = @Description, [PropertyValue] = @PropertyValue, [PropertyValueDataType] = @PropertyValueDataType, [PropertyValueUnitOfMeasure] = @PropertyValueUnitOfMeasure, [LastModified] = @LastModified WHERE (([ProductParameterGlobalId] = @Original_ProductParameterGlobalId) AND ([ProductSegmentGlobalId] = @Original_ProductSegmentGlobalId) 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_PropertyValueDataType = 1 AND [PropertyValueDataType] IS NULL) OR ([PropertyValueDataType] = @Original_PropertyValueDataType)) AND ((@IsNull_PropertyValueUnitOfMeasure = 1 AND [PropertyValueUnitOfMeasure] IS NULL) OR ([PropertyValueUnitOfMeasure] = @Original_PropertyValueUnitOfMeasure)) AND ([LastModified] = @Original_LastModified));
SELECT ProductParameterGlobalId, ProductSegmentGlobalId, ID, Name, Description, PropertyValue, PropertyValueDataType, PropertyValueUnitOfMeasure, LastModified FROM ProductParameter WHERE (ProductParameterGlobalId = @ProductParameterGlobalId) ORDER BY ProductParameterGlobalId

Jennifer
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16399882
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
0
 

Author Comment

by:jenniferw
ID: 16399955
No...

But I'm using a dataView upon the dataset, perhaps there is a problem with that?

Jennifer
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16399969
Are you using the DataView to filter and sort?

Bob
0
 

Author Comment

by:jenniferw
ID: 16400018
Yes...Hmmm...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16400196
Are you thinking, scratching your head, pondering options, what?

Bob
0
 

Author Comment

by:jenniferw
ID: 16400271
Yes....
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16400481
Ok, when you're done and you want to share some information with me, just let me know ;)

Bob
0
 

Author Comment

by:jenniferw
ID: 16415113
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(object sender, System.EventArgs e)
{
    try
    {

        DataRowCollection ds = dsProductParameter.ProductParameter.Rows;
        DataRowCollection dv = dataViewProductParameter.ToTable().Rows;

        for (int i = 0; i < ds.Count; i++)
        {
            for (int j = 0; j < dv.Count; j++)
            {

                if (dv[i]["ProductParameterGlobalID"] == ds[j]["ProductParameterGlobalID"])
                {
                   // Copy values from datagrid to dataset
                   ds[j]["ID"] = ((TextBox)ProductParameterGrid.Items[i].Cells[2].Controls[3]).Text;
                   ds[j]["Name"] = ((TextBox)ProductParameterGrid.Items[i].Cells[3].Controls[3]).Text;
                   ds[j]["Description"] = ((TextBox)ProductParameterGrid.Items[i].Cells[4].Controls[3]).Text;
                   ds[j]["PropertyValue"] = ((TextBox)ProductParameterGrid.Items[i].Cells[5].Controls[3]).Text;
                   ds[j]["PropertyValueDataType"] = ((TextBox)ProductParameterGrid.Items[i].Cells[6].Controls[3]).Text;
                   ds[j]["PropertyValueUnitOfMeasure"] = ((TextBox)ProductParameterGrid.Items[i].Cells[7].Controls[3]).Text;
                 }
            }

            dbcInterface.UpdateProductParameter(dsProductParameter);
     }
     ................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....


0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 16416576
If the DataGrid is bound to the DataView, then you need to process those rows, and not the complete set of rows for the entire DataTable.

Bob
0
 

Author Comment

by:jenniferw
ID: 16416939
Thank's for helping...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question