Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problems with CommandBuilder
Message
 
To
27/11/2004 22:07:13
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00965146
Message ID:
00965518
Views:
12
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform