473,624 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bound Access database update and fill problem

1 New Member
I have a bound Access database which contains tables "Recipes", "Ingredient s" 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_ingredie nts table which I also update and try to refill. However when I then call the recipe_ingredie ntsAdapter.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 1217

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

Similar topics

3
1921
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 title, author or ISBN number from a Access database called "Books.mdb". When the user clicks Submit from the "Books.html" file (after inputting info in a text box and clicking the required box to define Title, Author or ISBN), the information is...
3
10045
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 social security number, thus the database doesn't recognize the id since it wasn't put in the database with the additional digits. Here is what it puts on the screen in the database:: ;XXXXXXXXX=0229? The x's stand for the social security...
1
5064
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 string into either the appsettings or a global settings module i get an error on the server.mappath part of the string. how can i get round this as i dont want to have to use a specific path for the web application. it seems that this should be...
2
1002
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 works, a new row is added into the access database table. My problem is that I need to know what the ID (from the autonumber) is for the row that is inserted. I can't do a query on the table for values that = "valueToInsert" because there can be more...
15
2545
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, modifications and deletions functions very well in the dataset. But impossible to transmit modifications in ACCESS database. Impossible to WRITE in database. Here is the code for data transmission from tableadapter to Access database :
1
1639
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 drop down, it tries to update the access db. This causes the db to lock itself and not allow anyother updates. What I would like to do is be able to update just the in memory datatable for each field then use an update button to update everything at...
1
2025
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 drop down, it tries to update the access db. This causes the db to lock itself and not allow anyother updates. What I would like to do is be able to update just the in memory datatable for each field then use an update button to update everything at...
1
1434
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 drop down, it tries to update the access db. This causes the db to lock itself and not allow anyother updates. What I would like to do is be able to update just the in memory datatable for each field then use an update button to update everything at...
1
3036
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 opened as shared mode (not exclusive), just *ONE* user can open it at a time. When the first users opens the database, a ldb file is created at the same place as the database file is, and another users are not able to open the database as long the...
0
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.