Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on adding records

Status
Not open for further replies.

trose178

Programmer
Nov 26, 2002
26
US
I am trying to add records to my ODBC MFC program and am using this code

void CPersonalView::OnNewaddress()
{
if(!CPersonalSet.Open())
return FALSE;
if(!CPersonalSet.CanAppend())
return FALSE; // No field values were set
!CPersonalSet.AddNew();
!CPersonalSet.m_Birthdate = strBirthdate;
!CPersonalSet.m_Email = strEmail;
!CPersonalSet.m_First_Name = strFirstName;
!CPersonalSet.m_Last_Name = strLastName;
!CPersonalSet.m_Middle_Initial = strMiddleInitial;
!CPersonalSet.m_Nickname = strNickname;
if(!CPersonalSet.Update())
{
AfxMessageBox("Record not added; no field values were set.");
return FALSE;
}

}

then i get the error of this:
C:\Program Files\Microsoft Visual Studio\My Projects\AddBookDB\PersonalView.cpp(253) : error C2275: 'CPersonalSet' : illegal use of this type as an expression
c:\program files\microsoft visual studio\my projects\addbookdb\personalset.h(12) : see declaration of 'CPersonalSet'

i understand what the error means but i dont understand how to fix it. If you can help it i would greatly appreciate it.

Tim,
Currently Studying in High School
 
Hi,

Your statement "if(!CPersonalSet.Open())" is expecting a boolean return value (or int at least) but this if I remember correctly is not the case. In fact does it return anything?






William
Software Engineer
ICQ No. 56047340
 
Is CPersonalSet really a variable (Or is it only a classname) ?

/JOlesen
 
I'm assuming that CPersonalSet is a class derived from CRecordset. At least that would make sense to me. The error

[tt]'CPersonalSet' : illegal use of this type as an expression[/tt]

means that CPersonalSet is a class, not an object. An object is an instance of a class. I don't use ODBC, but I imagine that somehow through the MFC interface, you will obtain a pointer to a CPersonalSet object or something.

Also, this makes me curious, why this is in your code:
[tt]
!CPersonalSet.AddNew();
!CPersonalSet.m_Birthdate = strBirthdate;
!CPersonalSet.m_Email = strEmail;
!CPersonalSet.m_First_Name = strFirstName;
!CPersonalSet.m_Last_Name = strLastName;
!CPersonalSet.m_Middle_Initial = strMiddleInitial;
!CPersonalSet.m_Nickname = strNickname;[/tt]

I hope you realize that ! is the logical Not operator, and even if those were valid expressions (I mean, even if you fixed the error described above) the ! does absolutely nothing. Maybe you forgot something, like maybe enclosing the expression in an if clause. Or something like that. I don't know, but maybe the ! operation gets optimized out anyway. I would still revise the code though.

[sub]I REALLY hope that helps.[/sub]
Will
 
the example i have looks like this but i couldnt figure out what the rsStudent in the coding was.

if(!rsStudent.Open())
return FALSE;
if(!rsStudent.CanAppend())
return FALSE; // No field values were set
rsStudent.AddNew();
rsStudent.m_Birthdate = strBirthdate;
rsStudent.m_Email = strEmail;
rsStudent.m_First_Name = strFirstName;
rsStudent.m_Last_Name = strLastName;

i couldnt figure out what rsStudent was because i found this on MSDN and it didnt specify what type of variable it was.

Tim,
Currently Studying in High School
 
Ah!

Well then I think you'll find that rsStudent is a Recordset Object, so my original posting will still hold true.

You will of course need a RecordSet object in order for the code to work. Best to review the MSDN article again.


William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top