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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only