Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Simple way to update recordsets (ADO+)?

Is there a simple mechanism to update data in ADO+?

In ADO, the recordset object makes life so easy - all the important objects
necessary to add or update data are a method or property of the
ADODB.Recordset object.

However, there seems to be no simple equivalent in ADO+ and it's far more
limited DataRow object. What I've done below is an attempt to modify a
DataRow object, and then update it. Granted, I haven't followed the
convoluted (and incomprehensible) example from the NGWS "How do I" series,
but should it really be necessary? If it ain't broke...

The below's large commented section, when uncommented, results in the error:

System.InvalidOperationException: Invalid attempt to update table 'Support'
with no key columns defined. at (bunch of System.Data.* objects)

Help!

void SubmitButton_Click(Object sender, EventArgs E)
{
//put the data into the database and update
SQLConnection myConnection = new SQLConnection
("User ID=ZX;Initial Catalog=IT;Data Source=TREX");
SQLDataSetCommand myCommand =
new SQLDataSetCommand("SELECT * from HelpDB WHERE Id = "
+ JobTicketLabel.Text, myConnection);

DataSet ds = new DataSet();
myCommand.FillDataSet(ds, "HelpDB");

DataRow dsRow = ds.Tables["HelpDB"].Rows.Find(JobTicketLabel.Text);
//update the data
dsRow["Location"]=BranchLocation.Text;
dsRow["Name"]=PersonsName.Text;
dsRow["ComputerName"]=ComputerName.Text;
dsRow["OSType"]=OSList.SelectedItem.Text;
dsRow["ProblemType"]=ProbTypeList.SelectedItem.Text;
dsRow["ProblemDesc"]=ProbDescLabel.Text;
dsRow["Source"]=SourceList.SelectedItem.Text;
dsRow["Priority"]=PriorityList.SelectedItem.Text;
dsRow["Advisor"]=TechnicianName.Text;
dsRow["Recommendations"]=CurrentRecs.Value;

/* try
{
myConnection.Open();
myConnection.BeginTransaction();
myCommand.Update(ds, "HelpDB");
myConnection.CommitTransaction();
Response.Write("DataSet transaction succeeded!");
}
catch(Exception e)
{
myConnection.RollbackTransaction();
Response.Write(e.ToString());
}
finally
{
myConnection.Close();
} */

}
[2289 byte] By [Richard K Bethell] at [2007-11-9 18:21:53]
# 1 Re: Simple way to update recordsets (ADO+)?
I have been using SQL statements to do all my updates.

Modifying the DataRow (if that's possible) would make things simpler/safer
in certain situations.. Let me know also if you figure it out.
Thomas Kadlec at 2007-11-11 22:28:54 >
# 2 Re: Simple way to update recordsets (ADO+)?
Ever thought about using a FoxPro COM object for data access? It is much
more flexible than ADO. In fact, disconnected ADO recordsets are based on
the Fox client side cursor.

Charlie

"Richard K Bethell" <cj434@freenet.carleton.ca> wrote in message
news:39b6af35@news.dev-archive.com...
> Is there a simple mechanism to update data in ADO+?
>
> In ADO, the recordset object makes life so easy - all the important
objects
> necessary to add or update data are a method or property of the
> ADODB.Recordset object.
>
> However, there seems to be no simple equivalent in ADO+ and it's far more
> limited DataRow object. What I've done below is an attempt to modify a
> DataRow object, and then update it. Granted, I haven't followed the
> convoluted (and incomprehensible) example from the NGWS "How do I" series,
> but should it really be necessary? If it ain't broke...
>
> The below's large commented section, when uncommented, results in the
error:
>
> System.InvalidOperationException: Invalid attempt to update table
'Support'
> with no key columns defined. at (bunch of System.Data.* objects)
>
> Help!
>
> void SubmitButton_Click(Object sender, EventArgs E)
> {
> //put the data into the database and update
> SQLConnection myConnection = new SQLConnection
> ("User ID=ZX;Initial Catalog=IT;Data Source=TREX");
> SQLDataSetCommand myCommand =
> new SQLDataSetCommand("SELECT * from HelpDB WHERE Id = "
> + JobTicketLabel.Text, myConnection);
>
> DataSet ds = new DataSet();
> myCommand.FillDataSet(ds, "HelpDB");
>
>
> DataRow dsRow =
ds.Tables["HelpDB"].Rows.Find(JobTicketLabel.Text);
> //update the data
> dsRow["Location"]=BranchLocation.Text;
> dsRow["Name"]=PersonsName.Text;
> dsRow["ComputerName"]=ComputerName.Text;
> dsRow["OSType"]=OSList.SelectedItem.Text;
> dsRow["ProblemType"]=ProbTypeList.SelectedItem.Text;
> dsRow["ProblemDesc"]=ProbDescLabel.Text;
> dsRow["Source"]=SourceList.SelectedItem.Text;
> dsRow["Priority"]=PriorityList.SelectedItem.Text;
> dsRow["Advisor"]=TechnicianName.Text;
> dsRow["Recommendations"]=CurrentRecs.Value;
>
> /* try
> {
> myConnection.Open();
> myConnection.BeginTransaction();
> myCommand.Update(ds, "HelpDB");
> myConnection.CommitTransaction();
> Response.Write("DataSet transaction succeeded!");
> }
> catch(Exception e)
> {
> myConnection.RollbackTransaction();
> Response.Write(e.ToString());
> }
> finally
> {
> myConnection.Close();
> } */
>
>
> }
>
>
>
>
Charles Fineblum at 2007-11-11 22:29:54 >
# 3 Re: Simple way to update recordsets (ADO+)?
> Ever thought about using a FoxPro COM object for
> data access?

Charles: Wouldn't I then have to distribute Fox runtime support, in addition
to my app's other runtime requirements? How much memory does it consume? How
do its memory requirements compare to those of ADO?
--
Phil Weber
Phil Weber at 2007-11-11 22:30:57 >
# 4 Re: Simple way to update recordsets (ADO+)?
Yes you will have to distribute the VFP runtime. Its about 8 megs. Sounds
like a hassel, but you pick up a lot. Ever wanted to subclass a recordset
to create custom data objects? VFP base cursor and data environments
objects can be subclassed.

Charlie

"Phil Weber" <pweber@dev-archive.com> wrote in message
news:39bc06ae$1@news.dev-archive.com...
> > Ever thought about using a FoxPro COM object for
> > data access?
>
> Charles: Wouldn't I then have to distribute Fox runtime support, in
addition
> to my app's other runtime requirements? How much memory does it consume?
How
> do its memory requirements compare to those of ADO?
> --
> Phil Weber
>
>
Charles Fineblum at 2007-11-11 22:31:51 >