Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem updating non-text fields with OleDb command
Message
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Problem updating non-text fields with OleDb command
Divers
Thread ID:
00694258
Message ID:
00694258
Vues:
54
I'm trying to learn ASP.NET by reading the on-line documentation and working through the "walkthroughs." I ran into a problem that I cannot seem to solve in "Walkthrough: Updating Data Using a Database Update Query in Web Forms" (located at ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbwlkwalkthroughupdatingdatausingdatabaseupdatequeryinwebforms.htm)

I followed the instructions closely, except that I used a Visual FoxPro table and OleDb classes instead of SQL Server. The table I used is the Products table in the "testdata" database that ships with VFP 7.0.

The web page has a drop-down list for choosing the product_id, which fills some text boxes from data fields. You edit the text boxes and click the button, which executes the update query.

Here is the command text of the OleDbCommand:

UPDATE products SET eng_name = ?, in_stock = ? WHERE (product_id = ?)

The product_id and eng_name fields are character type; in_stock is numeric. The corresponding OleDbParameterTypes are VarChar and Decimal.

Here is the code in the click method of the button:

// Get the parameter values from the drop-down list and text boxes
cmdProductsUpdate.Parameters["product_id"].Value = ddlProductID.SelectedItem.Text;
cmdProductsUpdate.Parameters["eng_name"].Value = txtEnglishName.Text;
cmdProductsUpdate.Parameters["in_stock"].Value = Convert.ToDecimal(txtInStock.Text);
// Execute the update query
oleDbConnection1.Open();
cmdProductsUpdate.ExecuteNonQuery();
oleDbConnection1.Close();

I get the following error at the ExecuteNonQuery() line: "Object reference not set to instance of object." It's not clear to me which object reference is at fault.

I tried setting the "in_stock" parameter to a decimal constant (6.0), but that gave the same error. If I omit the in_stock field from the query or replace it with a character field, the update works OK. Also, if I replace the update command with delete and insert commands, the delete works OK but the insert command fails just like the update command.

So I suppose the error has to do with setting the "in_stock" parameter correctly, but I don't see how else to do it. Any suggestions?
Thomas M. Lamm
Bradbury & Associates
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform