Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 13th, 2006, 04:51 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default This piece of code is giving an error

The code is giving the error:

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication2.exe

Additional information: Object reference not set to an instance of an object.


Here is the code:

OleDbConnection connToStore = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; User Id=; Password=; Data source= "+db_storage);
connToStore.Open();

string cmdstr = "INSERT INTO trans_table( dataElement1, dataElement2, transformationDetail )" + "VALUES ('"+listBox_for_db1.Items[indexOfItemUnderMouseToDrag].ToString()+"','"+listBox_for_db2.Items[indexOfItemUnderMouseToDrag].ToString()+"','"+textBox_for_transformation.Text+ "')";

this.adapt.InsertCommand.Connection = connToStore;
this.adapt.InsertCommand.CommandText = cmdstr;
this.adapt.InsertCommand.ExecuteNonQuery();

connToStore.Close();
MessageBox.Show("successful");

 
Old July 14th, 2006, 09:08 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please show your source in its entirety and including the line number of the error.
It looks as though you haven't defined an OleDbCommand, but I can't see what you're doing with the adapter ("this.adapt.").

Anyhow; take a look at the following tutorial:
ADO.NET: Retrieve Data using OLE DB: http://dotnetjunkies.com/QuickStartv...odtreader.aspx
Simple ADO.NET Database Read, Insert, Update and Delete using C#: http://www.codeproject.com/dotnet/si...0&select=37317

- Adam Kahtava [http://adam.kahtava.com]
 
Old July 15th, 2006, 09:18 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 106
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it also seem that u have not created the reference of adapt i.e. adapt variable do not have reference.

Bijgupt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about a piece of code chobo2 C# 2008 aka C# 3.0 8 November 30th, 2008 11:53 AM
How to delete a piece of code Charlie05 C# 2005 2 August 3rd, 2008 11:32 AM
Need help with a small piece of code (New to VB) kwik10z Excel VBA 2 October 12th, 2007 06:46 AM
This piece of code is giving an error sourik Classic ASP Databases 1 July 14th, 2006 09:10 PM
What does this piece of code do? mito_lal Oracle 1 July 11th, 2006 06:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.