473,324 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Bound Access database update and fill problem

I have a bound Access database which contains tables "Recipes", "Ingredients" and "Units". A linked table "Recipe ingredients" holds id references to each of these tables.

My problem occurs when importing a new recipe from a text file. I create the reipe first and call the adapter update for the recipes table and then refill it. Then I create an entry in the recipe_ingredients table which I also update and try to refill. However when I then call the recipe_ingredientsAdapter.Fill I get a "Object reference not set to an instance of an object" error which suggests a null value somewhere.

I have checked that all the data is valid. Also if I use Access to open the modified database file after the updates it is perfectly happy - so is my own programme if I re-run it using the modified database.

Any ideas where the error message may be coming from? Attached are code snippets from the relevant routines.

Thanks

Expand|Select|Wrap|Line Numbers
  1.     private int ImportRecipe(string rcp)
  2.     {          
  3.  
  4.         {
  5.         ....... Some text parsing of string rcp to extract the data values
  6.                 and create an ArrayList (AllIngs) of Ingredient strings
  7.         }
  8.  
  9.         // Create a new recipe row
  10.         recipesDataSet.RecipesDataTable table = (recipesDataSet.RecipesDataTable)recipesDataSet.Tables["Recipes"];
  11.         recipesDataSet.RecipesRow row = table.AddRecipesRow(title
  12.             ,foodrow
  13.             ,veggy
  14.             ,Preptime
  15.             ,nserve
  16.             ,ncal
  17.             ,nutrition
  18.             ,instructions
  19.             ,notes
  20.             ,bookrow
  21.             ,wheat
  22.             ,dairy
  23.             ,utensils
  24.             ,page);
  25.  
  26.         recipesTableAdapter.Update(table);
  27.         recipesTableAdapter.Fill(recipesDataSet.Recipes);
  28.  
  29.         // Now we have a new recipe id we can update other related table
  30.         int newid = (int)table.Rows[table.Count - 1]["RecipeID"];
  31.         UpdateRecipeIngredientsTable(ref AllIngs, newid);
  32.         return newid;
  33.     }
  34.  
  35.     private void UpdateRecipeIngredientsTable(ref ArrayList list, int recid)
  36.     {
  37.         recipesDataSet.Recipe_IngredientsDataTable table = (recipesDataSet.Recipe_IngredientsDataTable)recipesDataSet.Tables["Recipe Ingredients"];
  38.         int id = 0;
  39.         foreach (Ingredient ing in list) {
  40.             recipesDataSet.Recipe_IngredientsRow drow = (recipesDataSet.Recipe_IngredientsRow)table.NewRow();
  41.             drow["RecipeID"] = recid;
  42.             drow["IngredientID"] = ing.ingID;
  43.             drow["Quantity"] = ing.quantity.ToString();
  44.             drow["UnitID"] = ing.unitID;
  45.             drow["Order"] = ++id;
  46.             table.AddRecipe_IngredientsRow(drow);
  47.         }
  48.         recipe_IngredientsTableAdapter.Update(table);
  49.         try {
  50.             recipe_IngredientsTableAdapter.Fill(recipesDataSet.Recipe_Ingredients);
  51.         }
  52.         catch (Exception ex) {
  53.             MessageBox.Show(ex.Message);
  54.         }
  55.     }
  56.  
  57.  
Feb 26 '11 #1
0 1206

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: TrvlOrm | last post by:
I am having great difficulty in these asp scripts, using VBscript and JavaScript. I have 4 files that all need to be linked together. The first file "Books.html" - needs to search for a Book...
3
by: Cherry | last post by:
I have an ID Innovation card reader that I am trying to connect to my Access database. The first problem is that when I swipe the card through the reader, it reads the id but it adds digits to the...
1
by: Colin Graham | last post by:
i am currently developing an asp.net web application which is linked to an Access database. The main problem that i have is in creating a global connection string that i can use. When i put my...
2
by: anonymous | last post by:
Hi, excuse as I am new to this. I have an Access database with two columns. They are 1. ID which is an "autonumber" and the primary key 2. pkData which is a number I do the following. It...
15
by: philip | last post by:
On a form, I have a datagridview. This datagridview is constructed on a dataset filled by a tableadapter. The table adapter do very well what it must do when filling dataset. Insertions,...
1
by: tazdiver | last post by:
Hi All, I am having an issue with an windows application made from VB.NET 2003 which is using an access database. Basically the problem is that when the user updates a field on the app from a...
1
by: tazdiver | last post by:
Hi All, I am having an issue with an windows application made from VB.NET 2003 which is using an access database. Basically the problem is that when the user updates a field on the app from a...
1
by: tazdiver | last post by:
Hi All, I am having an issue with an windows application made from VB.NET 2003 which is using an access database. Basically the problem is that when the user updates a field on the app from a...
1
by: antonio.cuartas | last post by:
Hi all, I have an Access 2000 database file on a shared network (windows) drive which should be accessed by several users at the same time. The problem is that although the database is being...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.