eVC 3, ADOCE addNew 
Author Message
 eVC 3, ADOCE addNew

Hi,

I'm having dificulty inserting a rows in a recordset using ADOCE.
I'm opening it with the option adLockOptimistic and adOpenKeyset.
I can't have a recordset that I can write to...

here is a part of my code:

  hr = m_pRs->Supports( adAddNew , &vaB);
  ASSERT( vaB == VARIANT_TRUE );        // this fail????
  hr = m_pRs->get_EditMode(&nVal);
  hr = m_pRs->AddNew(valueString, vaValue);
  if ( FAILED(hr) )
  {
   hr = m_pRs->get_EditMode(&nVal);
   valueString.vt = VT_BSTR;//VT_I4;//VT_EMPTY;//VT_NULL;// | VT_BYREF ;
   strField = L"employeeID";
   bstr = strField.AllocSysString();
   valueString.bstrVal = bstr;
   vaValue.vt = VT_I4;
   vaValue.lVal = g_lUserID;

   hr = m_pRs->AddNew(valueString, vaValue);

   SysFreeString(bstr);

   GetError();
  }

Please let me know if you have a solution.

Regards

Gildas du Halgouet



Tue, 28 Dec 2004 08:35:47 GMT  
 eVC 3, ADOCE addNew
Well you don't actually do an Update do you ? In MFC it is

AddNew()
// New values
Update()

The example given for ADOCE AddNew method in the documentation also does an
Update

Dim rs, i, L1
Set rs = CreateObject("ADOCE.Recordset.3.0")
rs.Open "myTable", "", adOpenKeyset, adLockOptimistic
rs.AddNew "f1", "a"
rs.AddNew
rs.Fields("f1") = "b"
rs.Update
rs.Close
rs.Open "myTable"
For i = 0 To rs.RecordCount - 1
     L1 = L1 & rs.Fields("f1").Value
     rs.MoveNext
Next
rs.Close
MsgBox L1

It is most probably the Update which actually writes the record inserted
into the recordset ( AddNew ) to the actual physical data source. This is
how it works in every other database technology I've used with VC++
namely ODBC, DAO, ADO

Also why do you only alter the values if FAILED(hr) surely you want your
first AddNew to have SUCCEEDED ?

I would have thought it would have looked something like

hr = m_pRs->AddNew(valueString, vaValue);
   if ( SUCCEEDED(hr) )
   {
    valueString.vt = VT_BSTR;
    strField = L"employeeID";
    valueString.bstrVal = strField.AllocSysString();
    vaValue.vt = VT_I4;
    vaValue.lVal = g_lUserID;

    if ( FAILED( m_pRs->Update() )
    // Failed to write record from recordset into database

Quote:
}



Quote:
> Hi,

> I'm having dificulty inserting a rows in a recordset using ADOCE.
> I'm opening it with the option adLockOptimistic and adOpenKeyset.
> I can't have a recordset that I can write to...

> here is a part of my code:

>   hr = m_pRs->Supports( adAddNew , &vaB);
>   ASSERT( vaB == VARIANT_TRUE );        // this fail????
>   hr = m_pRs->get_EditMode(&nVal);
>   hr = m_pRs->AddNew(valueString, vaValue);
>   if ( FAILED(hr) )
>   {
>    hr = m_pRs->get_EditMode(&nVal);
>    valueString.vt = VT_BSTR;//VT_I4;//VT_EMPTY;//VT_NULL;// | VT_BYREF ;
>    strField = L"employeeID";
>    bstr = strField.AllocSysString();
>    valueString.bstrVal = bstr;
>    vaValue.vt = VT_I4;
>    vaValue.lVal = g_lUserID;

>    hr = m_pRs->AddNew(valueString, vaValue);

>    SysFreeString(bstr);

>    GetError();
>   }

> Please let me know if you have a solution.

> Regards

> Gildas du Halgouet



Tue, 28 Dec 2004 17:59:49 GMT  
 eVC 3, ADOCE addNew
Thanks for your answer. Actually, the reason I do the FAILED(hr), is because
it actually fail, and the recordset don't have the addnew allowed.
I actually use SQLServer CE, and reading the documentation more carefully, I
got the impression that the AddNew method is not supported with that
datasource type.

I'll build SQL INSERT and UPDATE, it will work just the same...

Thanks again for your help

Gildas


Quote:
> Well you don't actually do an Update do you ? In MFC it is

> AddNew()
> // New values
> Update()

> The example given for ADOCE AddNew method in the documentation also does
an
> Update

> Dim rs, i, L1
> Set rs = CreateObject("ADOCE.Recordset.3.0")
> rs.Open "myTable", "", adOpenKeyset, adLockOptimistic
> rs.AddNew "f1", "a"
> rs.AddNew
> rs.Fields("f1") = "b"
> rs.Update
> rs.Close
> rs.Open "myTable"
> For i = 0 To rs.RecordCount - 1
>      L1 = L1 & rs.Fields("f1").Value
>      rs.MoveNext
> Next
> rs.Close
> MsgBox L1

> It is most probably the Update which actually writes the record inserted
> into the recordset ( AddNew ) to the actual physical data source. This is
> how it works in every other database technology I've used with VC++
> namely ODBC, DAO, ADO

> Also why do you only alter the values if FAILED(hr) surely you want your
> first AddNew to have SUCCEEDED ?

> I would have thought it would have looked something like

> hr = m_pRs->AddNew(valueString, vaValue);
>    if ( SUCCEEDED(hr) )
>    {
>     valueString.vt = VT_BSTR;
>     strField = L"employeeID";
>     valueString.bstrVal = strField.AllocSysString();
>     vaValue.vt = VT_I4;
>     vaValue.lVal = g_lUserID;

>     if ( FAILED( m_pRs->Update() )
>     // Failed to write record from recordset into database
> }



> > Hi,

> > I'm having dificulty inserting a rows in a recordset using ADOCE.
> > I'm opening it with the option adLockOptimistic and adOpenKeyset.
> > I can't have a recordset that I can write to...

> > here is a part of my code:

> >   hr = m_pRs->Supports( adAddNew , &vaB);
> >   ASSERT( vaB == VARIANT_TRUE );        // this fail????
> >   hr = m_pRs->get_EditMode(&nVal);
> >   hr = m_pRs->AddNew(valueString, vaValue);
> >   if ( FAILED(hr) )
> >   {
> >    hr = m_pRs->get_EditMode(&nVal);
> >    valueString.vt = VT_BSTR;//VT_I4;//VT_EMPTY;//VT_NULL;// | VT_BYREF ;
> >    strField = L"employeeID";
> >    bstr = strField.AllocSysString();
> >    valueString.bstrVal = bstr;
> >    vaValue.vt = VT_I4;
> >    vaValue.lVal = g_lUserID;

> >    hr = m_pRs->AddNew(valueString, vaValue);

> >    SysFreeString(bstr);

> >    GetError();
> >   }

> > Please let me know if you have a solution.

> > Regards

> > Gildas du Halgouet



Tue, 28 Dec 2004 22:21:41 GMT  
 eVC 3, ADOCE addNew
Are you using version 3.0??  I had problems with 3.0.  I
don't remember if I had this exact same problem.  But my
problems were solved with version 3.1.  You can download
it from the micrsoft site.

Quote:
>-----Original Message-----
>Hi,

>I'm having dificulty inserting a rows in a recordset
using ADOCE.
>I'm opening it with the option adLockOptimistic and
adOpenKeyset.
>I can't have a recordset that I can write to...

>here is a part of my code:

>  hr = m_pRs->Supports( adAddNew , &vaB);
>  ASSERT( vaB == VARIANT_TRUE );        // this fail????
>  hr = m_pRs->get_EditMode(&nVal);
>  hr = m_pRs->AddNew(valueString, vaValue);
>  if ( FAILED(hr) )
>  {
>   hr = m_pRs->get_EditMode(&nVal);
>   valueString.vt =

VT_BSTR;//VT_I4;//VT_EMPTY;//VT_NULL;// | VT_BYREF ;

- Show quoted text -

Quote:
>   strField = L"employeeID";
>   bstr = strField.AllocSysString();
>   valueString.bstrVal = bstr;
>   vaValue.vt = VT_I4;
>   vaValue.lVal = g_lUserID;

>   hr = m_pRs->AddNew(valueString, vaValue);

>   SysFreeString(bstr);

>   GetError();
>  }

>Please let me know if you have a solution.

>Regards

>Gildas du Halgouet

>.



Sat, 01 Jan 2005 02:04:26 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help me to Insert varbinary with adoce (EVC)

2. eVC ++ Adoce Recordset's State property

3. Who Has Sample to Use ADOCE In EVC

4. ADOCE 3.1 and eVC 3.0

5. EVC ADOCE Recordset get value from data field

6. SQL error with ADOCE in EVC

7. ADOCE Connection Execute() with eVC++

8. ADOCE Programmin with eVC++ 3.0

9. ADOCE in eVC++

10. ADOCE 3.1 and eVC

11. eVC and SQL server CE / ADOCE

12. ADOCE, eVC++, ViaDB

 

 
Powered by phpBB® Forum Software