how can i use CRowset::Insert to insert data

how can i use CRowset::Insert to insert data

Post by RGF2aW » Sun, 16 Oct 2005 15:07:01


i have some objects like this:
CDataSource ds;
CSession ss;
CCommand<CDynamicsAccessor> rs;
and i successfully opened rs like this;
...//connect to MS-SQL Server
CDBPropSet* DBPropSet = new CDBPropSet(DBPROPSET_ROWSET);
DBPropSet->AddProperty(DBPROP_IRowsetUpdate, true);

DBPropSet->AddProperty(DBPROP_UPDATABILITY,DBPROPVAL_UP_CHANGE|DBPROPVAL_UP_DELETE| DBPROPVAL_UP_INSERT);

DBPropSet->AddProperty(DBPROP_CANSCROLLBACKWARDS, true);
DBPropSet->AddProperty(DBPROP_CANFETCHBACKWARDS, true);

rs.Open(ss, "SELECT name FROM oletest", (DBPROPSET*)DBPropSet);

how can i use rs.Insert() to insert data ?
i tried something like this:
...//a while-statement display all the rows in rs, it exit on rs.MoveNext
return DB_S_ENDOFROWSET

LPWSTR pwszName = (LPWSTR)rs.GetValue(1);
wcscpy(pwszName, L"uu");
rs.SetStatus(1, DBSTATUS_S_OK);
rs.Insert();

the rs.Insert() returns S_OK, but when i use rs.Updata(), it fails!!
what's the problem??
 
 
 

how can i use CRowset::Insert to insert data

Post by TGlue » Wed, 19 Oct 2005 05:51:10

Hi,

For Update(), you have to cal Setdate() and then call Update(), its a
delayed update..

 
 
 

how can i use CRowset::Insert to insert data

Post by RGF2aW » Wed, 19 Oct 2005 11:38:03

quite strange... rs.Insert now returns DB_E_ERRORSOCCURED, would u plz give a
little example on this ? u said i should calll Setdate(), u mean i should do
like this,

rs.Insert();
rs.Setdate();
rs.Update();

is it ??
 
 
 

how can i use CRowset::Insert to insert data

Post by RGF2aW » Wed, 19 Oct 2005 11:55:02

now i tried something like this, but still fail
LPWSTR pwszName = (LPWSTR)rs.GetValue(1);
wcscpy(pwszName, L"uu");
rs.SetStatus(1, DBSTATUS_S_OK);
rs.ReleaseRows();//if i dont use this, Insert() will return
DB_E_ROWSNOTRELEASE
rs.Insert();
rs.SetData();//return DB_E_BADROWHADLE
rs.Update();

could u help me?
 
 
 

how can i use CRowset::Insert to insert data

Post by TGlue » Wed, 19 Oct 2005 23:46:03

Hi,

sorry for the misunderstanding ..

First of all, what u want ? update () or insert () ?

I said, for Update(), u have to call Setdata() and then call update() becoz
u set IRowsetUpdate (delayed update)

Forinsert, call insert() .

For both update and insert u have to set the dwxxxxxStatus / dwxxxxLength
fields before the call (update / insert)

moreover, check the data type and size for all the fields

hope this helps ..

Linz
 
 
 

how can i use CRowset::Insert to insert data

Post by RGF2aW » Thu, 20 Oct 2005 14:01:01

yes, i want to do Insert.
u mean i need call Setdate() or Update() after Insert?
i set both the Status and Length, but still fail...would you please give me
a sample or something? thanks a lot!!!