log in 
Author Message
 log in

I'm new to windows programming.  Does anyone know the best
way to have a user sign in where the log in would
determine what the user would be able to see and do in the
application that I am writing? thank you in advance for
whatever help you can provide.


Sat, 30 Oct 2004 04:06:27 GMT  
 log in


Fri, 19 Jun 1992 00:00:00 GMT  
 log in
I use IADORecordBinding' methord to add a new record and updata a
record,when doing this,the return (hr) is error,and no record change,i want
your help
thanks


Sat, 30 Oct 2004 12:06:54 GMT  
 log in
Mr. Dong Chun-xi

Are you binding the status fields for each of the bound variables?  In other
words, do you use the ADO_VARIABLE_LENGTH_ENTRY2 macro for binding char
variables?

Prior to calling the AddNew method on the CADORecordBinding derived object,
have you set the status fields to 0 (or the adFldOK constant as defined in
icrsint.h)?  You should have something like this:

strcpy(rs.m_ch_lname,"BUSH");
strcpy(rs.m_ch_fname,"GEORGE");
rs.m_ul_fnameStatus = adFldOK;
rs.m_ul_lnameStatus = adFldOK;
rs.AddNew();

I hope this helps.

If you are still having problems, please post your code here - and we will have
a look at it.  Most likely we will be able to resolve your problems rather
quickly.

all the best,
roy fine


Quote:
> I use IADORecordBinding' methord to add a new record and updata a
> record,when doing this,the return (hr) is error,and no record change,i want
> your help
> thanks



Sat, 30 Oct 2004 13:03:49 GMT  
 log in
I use IADORecordBinding' methord to add a new record and updata a
record,when doing this,the return (hr) is error,and no record change,i want
your help
thanks

below is my sample code:
 ::CoInitialize(NULL);
 _ConnectionPtr pConn("ADODB.Connection");
 _RecordsetPtr  pRsSample("ADODB.Recordset");
 IADORecordBinding *picSample=NULL;
 CCustomRec Sample;
 HRESULT hr;
 try{
  hr=pConn->Open("dsn=mydata;","","",adOpenUnspecified);
  if(FAILED(hr))_com_issue_error(hr);
  strSql="select * from sample";

hr=pRsSample->Open(LPCTSTR(strSql),(IDispatch*)pConn,adOpenDynamic,adLockOpt
imistic,adCmdText);
  if(FAILED(hr))_com_issue_error(hr);
  hr=pRsSample->QueryInterface (__uuidof(IADORecordBinding),(LPVOID
*)&picSample);
  if(FAILED(hr))_com_issue_error(hr);
  hr=picTrace->BindToRecordset(&Sample);
  if(FAILED(hr))_com_issue_error(hr);
  Sample.m_age=180;
  Sample.m_weight=80;
  Sample.ageStatus=adFldOK;
  Sample.weightStatus=adFldOK;
  hr=picSample->AddNew(&Sample);
  if(FAILED(hr))_com_issue_error(hr);
  while(VARIANT==pRsSample->adoEOF){
   if(Sample.m_age<30){
    Sample.m_age=40;
    hr=picSample->Update(&Sample);
    if(FAILED(hr))_com_issue_error(hr);
   }
  }

  picSample->Release();
  picSample=NULL;
  pRsSample->Close();
  pRsSample=NULL;
  pConn->Close();
  pConn=NULL;
 }
 catch(_com_error &e){
  dump_com_error(e);
 }

 CoUninitialize();
 return true;

----------------------------------------------------------------------------
--
class CCustomRec : public CADORecordBinding
{
 BEGIN_ADO_BINDING(CCustomRec)
  file://ADO_FIXED_LENGTH_ENTRY(1,adUnsignedInt,m_id,idStatus,false)
  ADO_FIXED_LENGTH_ENTRY(2,adSmallInt,m_age,ageStatus,false)
  ADO_FIXED_LENGTH_ENTRY(3,adSmallInt,m_weight,weightStatus,false)
 END_ADO_BINDING()
public:
 file://DWORD m_id;
 file://ULONG idStatus;
 __int16 m_age;
 ULONG ageStatus;
 __int16 m_weight;
 ULONG weightStatus;

Quote:
};

----------------------------------------------------------------------------
---
table Sample
id primary key identify(1,1) not null;
age smallint
weight smallint


Sat, 30 Oct 2004 17:42:17 GMT  
 log in


Fri, 19 Jun 1992 00:00:00 GMT  
 log in

Quote:

>I'm new to windows programming.  Does anyone know the best
>way to have a user sign in where the log in would
>determine what the user would be able to see and do in the
>application that I am writing? thank you in advance for
>whatever help you can provide.

Assuming you're usiung MFC, put a dialog in the Document's
constructor. Then do a look-up against username/password combination &
have a numeric access level in there. In the OnUpdateUI... methods,
chekc the access level to see if the menu option should be greyed out
or not.

HTH

Paul.
-------------------------------------------
Expressed opinions are usually my own.
Especially if they're any good (of course).
-------------------------------------------



Sat, 30 Oct 2004 21:29:22 GMT  
 log in


Fri, 19 Jun 1992 00:00:00 GMT  
 log in
Mr. Dong Chunxi,

Please change the ModifyFlag in the bind macro to TRUE if you want to do
updates or additions to the underlying table using the CADORecordBinding
approach.

I noticed that you are using the lowercase builtin/integral C++ boolean type
in the macro (i.e. false).  This field in declared BOOL in the
ADO_BINDING_ENTRY struct, and we should be using the legacy C TRUE or
FALSE(i.e. not 0, and 0), not true or false.  Note that BOOL is an int (4
bytes) and bool is 1 byte - they are two different types.

Additionally, if I may offer another suggestion or two:
1.  All text parameters passed to ADO are expected to be BSTRs.  It is much
more efficient to declare these as BSTRs and then release them when you are
through.  If you prefer to have managed BSTR case, use the _bstr_ class
instead.
2. The second argument on the Recordset.Open method is a variant, typically
a reference to an opened Connection object (i.e. implements the IDispatch
interface).  The Recordset.Open method expects that reference to be
reference counted (i.e. a call to AddRef on the interface prior to the
passing in as an argument).  Simply sticking a connection object with
requisite cast is not sufficient.  Either call AddRef on the connection
interface, or use the _variant_t((IDispatch *)cnxt,true) approach, or use
the Recordset.PutRefActiveConnection(cnxt) method.
3.  I would also suggest that you use the wrapper class methods, and have
all ADO access code within a try/catch block.  For instance, the Open method
never returns with an HRESULT error -- if there is an error, it throws an
exception.  To manage HRESULTS locally, you MUST call the raw_xxxx methods.
4.  I would never recommend using the Select * syntax for a recordset,
especially when using ordinal bindings.  Explicitly identify the fields you
are selecting, then match the bind variable accordingly.
5.  Finally, make sure you have a unique record before attempting to do an
update -- this implies that you select enough fields to guarantee uniquess,
or preferrably, include a primary key or unique index in the SQL Select
statement.    If you select age and weight, and then subsequently change the
weight to 135 of a record with age=40 and weight=130, do you want every
record with age 40 and weight 130 to be changed to age 40 and weight 135.
If your Select statement  also includes a primary key, your intentions
become a bit more intuitive..

For the Recordset Open, I might suggest something like the following:
/* ************************************ */
try{
...
  BSTR strSql = ::SysAllocString(L"Select age,weight From Sample");
  pRsSample->PutRefActiveConnection(pConn);

pRsSample->Open(strSql,vtMissing,adOpenDynamic,adLockOptimistic,adCmdText);
  ::SysFreeString(strSql);
  ...
  }
catch(_com_error $&e){
  _bstr_t desc = e.Description();
  _bstr_errm = e.ErrorMessage();
  printf("\n\nError in ADO:\nDescription:%s\nErrorMessage:%s",(char
*)desc,(char *)errm);
  }

I hope this helps a bit.

best regards
roy fine


Quote:

> thanks for your help;
> below is my sample code;
> the value of hr when call addnew or update is -2146825069,the error code
is
> 800a0c93 and error meaning is adErrIllegalOpention.
> thanks you;

>  ::CoInitialize(NULL);
>  _ConnectionPtr pConn("ADODB.Connection");
>  _RecordsetPtr  pRsSample("ADODB.Recordset");
>  IADORecordBinding *picSample=NULL;
>  CCustomRec Sample;
>  HRESULT hr;
>  try{
>   hr=pConn->Open("dsn=mydata;","","",adOpenUnspecified);
>   if(FAILED(hr))_com_issue_error(hr);
>   strSql="select * from sample";

hr=pRsSample->Open(LPCTSTR(strSql),(IDispatch*)pConn,adOpenDynamic,adLockOpt

- Show quoted text -

Quote:
> imistic,adCmdText);
>   if(FAILED(hr))_com_issue_error(hr);
>   hr=pRsSample->QueryInterface (__uuidof(IADORecordBinding),(LPVOID
> *)&picSample);
>   if(FAILED(hr))_com_issue_error(hr);
>   hr=picTrace->BindToRecordset(&Sample);
>   if(FAILED(hr))_com_issue_error(hr);
>   Sample.m_age=180;
>   Sample.m_weight=80;
>   Sample.ageStatus=adFldOK;
>   Sample.weightStatus=adFldOK;
>   hr=picSample->AddNew(&Sample);
>   if(FAILED(hr))_com_issue_error(hr);
>   while(VARIANT==pRsSample->adoEOF){
>    if(Sample.m_age<30){
>     Sample.m_age=40;
>     hr=picSample->Update(&Sample);
>     if(FAILED(hr))_com_issue_error(hr);
>    }
>   }

>   picSample->Release();
>   picSample=NULL;
>   pRsSample->Close();
>   pRsSample=NULL;
>   pConn->Close();
>   pConn=NULL;
>  }
>  catch(_com_error &e){
>   dump_com_error(e);
>  }

>  CoUninitialize();
>  return true;

> --------------------------------------------------------------------------
--
> --
> class CCustomRec : public CADORecordBinding
> {
>  BEGIN_ADO_BINDING(CCustomRec)
>   file://ADO_FIXED_LENGTH_ENTRY(1,adUnsignedInt,m_id,idStatus,false)
>   ADO_FIXED_LENGTH_ENTRY(2,adSmallInt,m_age,ageStatus,false)
>   ADO_FIXED_LENGTH_ENTRY(3,adSmallInt,m_weight,weightStatus,false)
>  END_ADO_BINDING()
> public:
>  file://DWORD m_id;
>  file://ULONG idStatus;
>  __int16 m_age;
>  ULONG ageStatus;
>  __int16 m_weight;
>  ULONG weightStatus;
> };
> --------------------------------------------------------------------------
--
> ---
> table Sample
> id primary key identify(1,1) not null;
> age smallint
> weight smallint




- Show quoted text -

Quote:
> I use IADORecordBinding' methord to add a new record and updata a
> record,when doing this,the return (hr) is error,and no record change,i
want
> your help
> thanks

> below is my sample code:
>  ::CoInitialize(NULL);
>  _ConnectionPtr pConn("ADODB.Connection");
>  _RecordsetPtr  pRsSample("ADODB.Recordset");
>  IADORecordBinding *picSample=NULL;
>  CCustomRec Sample;
>  HRESULT hr;
>  try{
>   hr=pConn->Open("dsn=mydata;","","",adOpenUnspecified);
>   if(FAILED(hr))_com_issue_error(hr);
>   strSql="select * from sample";

hr=pRsSample->Open(LPCTSTR(strSql),(IDispatch*)pConn,adOpenDynamic,adLockOpt

- Show quoted text -

Quote:
> imistic,adCmdText);
>   if(FAILED(hr))_com_issue_error(hr);
>   hr=pRsSample->QueryInterface (__uuidof(IADORecordBinding),(LPVOID
> *)&picSample);
>   if(FAILED(hr))_com_issue_error(hr);
>   hr=picTrace->BindToRecordset(&Sample);
>   if(FAILED(hr))_com_issue_error(hr);
>   Sample.m_age=180;
>   Sample.m_weight=80;
>   Sample.ageStatus=adFldOK;
>   Sample.weightStatus=adFldOK;
>   hr=picSample->AddNew(&Sample);
>   if(FAILED(hr))_com_issue_error(hr);
>   while(VARIANT==pRsSample->adoEOF){
>    if(Sample.m_age<30){
>     Sample.m_age=40;
>     hr=picSample->Update(&Sample);
>     if(FAILED(hr))_com_issue_error(hr);
>    }
>   }

>   picSample->Release();
>   picSample=NULL;
>   pRsSample->Close();
>   pRsSample=NULL;
>   pConn->Close();
>   pConn=NULL;
>  }
>  catch(_com_error &e){
>   dump_com_error(e);
>  }

>  CoUninitialize();
>  return true;

> --------------------------------------------------------------------------
--
> --
> class CCustomRec : public CADORecordBinding
> {
>  BEGIN_ADO_BINDING(CCustomRec)
>   file://ADO_FIXED_LENGTH_ENTRY(1,adUnsignedInt,m_id,idStatus,false)
>   ADO_FIXED_LENGTH_ENTRY(2,adSmallInt,m_age,ageStatus,false)
>   ADO_FIXED_LENGTH_ENTRY(3,adSmallInt,m_weight,weightStatus,false)
>  END_ADO_BINDING()
> public:
>  file://DWORD m_id;
>  file://ULONG idStatus;
>  __int16 m_age;
>  ULONG ageStatus;
>  __int16 m_weight;
>  ULONG weightStatus;
> };
> --------------------------------------------------------------------------
--
> ---
> table Sample
> id primary key identify(1,1) not null;
> age smallint
> weight smallint



Sat, 30 Oct 2004 22:32:37 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. how to log error to Event Log for ATL

2. Log in \ log out - indication.

3. Easy way to log to event log?

4. Logging into NT Error Log

5. auto log in to win9x after logging out user?

6. c# Trouble Setting the Event Log Display Name for my event log.

7. Error in while writting to Event Log

8. Error while writting in Event Log

9. Network Connection, Logged on To Net Pinging

10. Web Service writing Event Log entries?

11. Event Log Rights

12. Getting Current logged on User Name

 

 
Powered by phpBB® Forum Software