Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems with CommandBuilder
Message
De
29/11/2004 15:48:50
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00965146
Message ID:
00965520
Vues:
11
Gerard,

It's because you didn't instantiate oAd, although you thought you did.

In your GetData method you have:
OleDbDataAdapter oAd = new OleDbDataAdapter(this.sSelectString ,oCon);
when you should have had:
this.oAd = new OleDbDataAdapter(this.sSelectString ,oCon);
~~Bonnie



>Hi, thanks for your replies which are much appreciated.
>I am still grappling with .net and am now getting following error message on the select command when I run the program:
>
>An unhandled exception of type 'System.NullReferenceException' occurred
>Add inf: Object Ref not set to an instance of an object
>My class code is :
>--------------------------------------------------
>using System;
>using System.Data;
>using System.Data.SqlClient;
>using System.Data.OleDb;
>
>public class BusObj
>{
>	protected OleDbConnection oCon ;
>	protected string sSelectString ;
>	protected string sTableName = "";
>	protected string sFields = "*";
>	protected System.Collections.ArrayList	cReqFields = new System.Collections.ArrayList(0);
>	protected OleDbDataAdapter oAd;
>
>	public BusObj()
>	{
>	}
>
>	public virtual DataSet GetData()
>	{
>		DataSet oDS = new DataSet();
>		this.oCon = new OleDbConnection(@"Provider=vfpoledb.1;Data Source=C:\ISRC\DFISR.dbc");
>		this.oCon.Open();
>		// Error handling missing!!!
>        this.sSelectString = "SELECT " + this.sFields + " FROM " + this.sTableName;
>		OleDbDataAdapter oAd = new 	OleDbDataAdapter(this.sSelectString ,oCon);
>		oAd.Fill(oDS,this.sTableName);
>		this.oCon.Close();
>		return oDS;
>	}
>
>	public virtual int Save(DataSet oDS)
>	{
>		//create a CommandBuilder and build the delete,update and insert commands
>		OleDbCommandBuilder CommandBuilder = new OleDbCommandBuilder(oAd);
>		oAd.SelectCommand = new OleDbCommand(this.sSelectString,this.oCon);
>		oAd.DeleteCommand = CommandBuilder.GetDeleteCommand();
>		oAd.UpdateCommand = CommandBuilder.GetUpdateCommand();
>		oAd.InsertCommand = CommandBuilder.GetInsertCommand();
>
>		//Update the data in the dataset
>		int RowsUpdated = oAd.Update(oDS);
>		return RowsUpdated;
>	}
>}
>---------------------------------------------------
>
>The error occurs on the oAd.SelectCommand..... line
>
>Regards,
>Gerard
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform