|
This is really helpful for a beginner. Could you please explain some basics on DSN?
Jes
|
|
|
|
|
Can any one please explain me how???
|
|
|
|
|
Hello,
To the test.mdb file, I added a new table. The name of the table is Makes. This table contains 3 fields: ID, CatID, and Make. In the code, I changed the value of SqlString to "SELECT Categories.Category, Makes.Make FROM Categories, Makes WHERE Categories.CatID=Makes.CatID". When I run the program, I get a message box with the following message: Database error: Type mismatch in expression. Any help is appreciated.
Mike
|
|
|
|
|
Please help me to create MS Access file with the help of mfc code(ODBC)
|
|
|
|
|
Hi,
Even I've used the same method.
How do I get the connection mentioned in main dlg box,apply to even modal dlgboxes.
My problem is Ican dynamically retrieve records in main dlgbox but failed to do so in modal dlgboxes.I've included main dlgbox header file,even then it doesn't work.
WHT could be the problem?
swapna_signsin
|
|
|
|
|
i am an engg.student of comp.science i need to make connectivity of c/c++ with access/sql database . i need the code that can run on a compiler which is common to use like dev-c++ etc
if u an help me then plz do
|
|
|
|
|
Hi, I was looked for what is offered by CDatabase in MS Access
even after adding the process.h still I get this Error
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/database.exe : fatal error LNK1120: 2 unresolved externals
Any Help would be appreciated. I am using this under Win32 API programming:
#include <afxdb.h>
#include <odbcinst.h>
#include <process.h>
{
....some other codes
}
void FillListBox (HWND hwndList)
{
CDatabase database;
CString SqlString;
CString sCatID, sCategory;
CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString sDsn;
CString sFile = "c:\\test\\Test.mdb";
int iRec = 0;
// Build ODBC connection string
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
TRY
{
// Open the database
database.Open(NULL,false,false,sDsn);
// Allocate the recordset
CRecordset recset( &database );
// Build the SQL statement
SqlString = "SELECT CatID, Category "
"FROM Categories";
// Execute the query
recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);
// Loop through each record
while( !recset.IsEOF() )
{
// Copy each column into a variable
recset.GetFieldValue("CatID",sCatID);
recset.GetFieldValue("Category",sCategory);
/*
// I thought this SendMessage will work!
CString szFormatId, szFormatCat;
szFormatId.Format("%d",sCatID);
szFormatCat.Format("%s",sCategory);
SendMessage (hwndList, LB_ADDSTRING, 0, (LPARAM) szFormatId) ;
SendMessage (hwndList, LB_ADDSTRING, 0, (LPARAM) szFormatCat) ;
// But it give following error
// : error C2440: 'type cast' : cannot convert from 'class CString' to 'long'
// No user-defined-conversion operator available that can perform this conversion,
// or the operator cannot be called
*/
// goto next record
recset.MoveNext();
}
// Close the database
database.Close();
}
CATCH(CDBException, e)
{
// If a database exception occured, show error msg
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}
|
|
|
|
|
You need to include MFC. In the project options (I believe) there is an option on one of the tabs that says Include MFC in a Static Library. That button needs to be checked and then the project should compile.
Josh
|
|
|
|
|
Please add these header files and try, hopefully it will work.
#include "afxdb.h"
#include "odbcinst.h"
-- modified at 13:25 Monday 31st October, 2005
|
|
|
|
|
Hello,
It appears as soon as it gets to recSet.Open(...) I get this error :
"No Columns were bound prior to calling SQL FetchScroll/SqlExtendedFetch"
any idea what causing this ?
thanks
|
|
|
|
|
Sure, I also notice that CRecordset can not open with "Dynaset". This problem seems having no solution. This means you can not update the tables in Access through CRecordset. ODBC can not be used anymore?
|
|
|
|
|
i have done a mfc app, that lists all the datas of a particular database(MS Access) in a List control box... now i want to get the particular record when clicking on an items listed in List Control Box.... how can i do this ??
anybody please help.. if possible explain in details sir...
thanks in advance....
sakesh
|
|
|
|
|
GetFieldValue supports Unicode?
I have some unicode data in my database. After this function call ( GetFieldValue("Descript",sDescript) I get always "??????" characters. For debugging I have used
fout << (const char*) sDescript << endl;
tnx
|
|
|
|
|
You have to use UNICODE with the rest of your program, too, the string from the database doesn't get magically converted to ANSI.
Make sure sDescript is a CString.
GetFieldValue( _T("Descript"),sDescript);
fout << (LPCTSTR)sDescript << endl;
Better yet, use the MFC functions for file handling.
|
|
|
|
|
Can a MS Access database be password protected? And if so, how do deal with that when trying to read the database in your program?
|
|
|
|
|
Hi, please help.
I'm a novice coder and the database connection method identified on this page is practically exactly what i needed for my group's application. The following code is an attempt to connect to an access database on my hard drive, check a value in a certain field of a certain table, update that field if its value is 'no' and add data into some other fields. Here's the code
#include <stdio.h>
#include <stdlib.h>
#include <afxdb.h>
extern "C" {
#include <odbcinst.h>
}
void main()
{
CDatabase database;
CString sDriver = "Microsoft Access Driver (*.mdb)";
CString sDsn;
CString sFile = "c:\\WPS\\WPSData.mdb";
CString SqlString, SqlString1;
CString varValue;
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
TRY
{
database.Open(NULL,false,false,sDsn);
CRecordset recset(&database);
SqlString = "SELECT * FROM Member1234";
recset.Open(CRecordset::forwardOnly,SqlString);
while(recset.IsEOF()!=1)
{
recset.MoveNext();
}
recset.GetFieldValue("ParkCheck", varValue);
if(varValue = "No")
{
SqlString1.Format("UPDATE Member1234 SET [ParkCheck] = #%s#", "Yes");
database.ExecuteSQL(SqlString1);
SqlString1.Format("INSERT INTO (ParkID, Date, ParkInTime) VALUES (1, '7/04/2004', '8.30pm')");
database.ExecuteSQL(SqlString1);
if(!recset.Update())
{
AfxMessageBox("Record not added");
}
}
else
{
SqlString1.Format("INSERT INTO (ParkOutTime) VALUES ('8.30pm')");
database.ExecuteSQL(SqlString1);
if(!recset.Update())
{
AfxMessageBox("Record not added");
}
}
database.Close();
}
CATCH(CDBException, e)
{
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}
I get the following unresolved external linker errors and i have NO idea why??? There's 33 of them, so please bear with me
[Linker Error] Unresolved external '__stdcall CException::operator delete(void *)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CDBException::~CDBException()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CException::~CException()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external '__stdcall CObject::operator delete(void *)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CObject::~CObject()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CString::~CString()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CDatabase::~CDatabase()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CPtrList::~CPtrList()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external '__stdcall AfxTryCleanup()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CRecordset::~CRecordset()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CMapPtrToPtr::~CMapPtrToPtr()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CDatabase::CDatabase()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CString::CString(const char *)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CString::CString()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'AFX_EXCEPTION_LINK::AFX_EXCEPTION_LINK()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CDatabase::Open(const char *, int, int, const char *, int)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CRecordset::CRecordset(CDatabase *)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CRecordset::MoveNext()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CRecordset::IsEOF() const' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CRecordset::Open(unsigned int, const char *, unsigned long)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CRecordset::CanAppend() const' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CRecordset::GetFieldValue(const char *, CString&)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CString::operator =(const char *)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CString::Format(const char *, ...)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CDatabase::ExecuteSQL(const char *)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CRecordset::Update()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CDatabase::Close()' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CDBException::classCDBException' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CObject::IsKindOf(const CRuntimeClass *) const' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external '__stdcall AfxAssertFailedLine(const char *, int)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external '__stdcall operator +(const char *, const CString&)' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external 'CString::operator const char *() const' referenced from C:\WPS\LISTENING.OBJ
[Linker Error] Unresolved external '__stdcall AfxMessageBox(const char *, unsigned int, unsigned int)' referenced from C:\WPS\LISTENING.OBJ
Any help or solution would be greatly appreciated. Thankyou in advance
|
|
|
|
|
Anyone knows how to resolve this problem ?
When I Set
CRecordset.m_strFilter = "Date=#8/01/2004#"; (or other date)
it don`t works
It not give any records
Thanks
|
|
|
|
|
You have to use:
CRecordset.m_strFilter = "Date >= #8/01/2004 00:00:00# AND Date <= #8/01/2004 23:59:59#";
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
if the Data is date\time style?
if so, the date 8/01/2004 should include hour,minute and second.
|
|
|
|
|
i have problems linkin the edit box member variables to my database, how to i display the data into the edit box? i am using Crecordset and added m_pSet variable....Urgent!
|
|
|
|
|
hi,
There is a small error in this program and it is recoverable.
Description:- For iterating through the table to go to next record author used
while(!recset.IsEOF)
but this is wrong. If you try this you will only be able to fetch only one record. The solution to this problem is simple
while(recset.IsEOF()!=1)
happy coding bye, Have a nice Day!
cobra
|
|
|
|
|
You must be doing something (else) wrong. The statement:
while (! recset.IsEOF())
is correct in all aspects. If it is only returning one row for you, something else is wrong.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Which are:
1) Can you change the the colour (UK English ) of each row of a list control?
2) How can be serialised?
about Visual C++ being complicated
|
|
|
|
|
int fileid=1;
SqlString = "SELECT * "
"FROM Artefact "
"WHERE Id= fileid";
the 'WHERE' clause don't seem to be able to 'extract' out my variable. How do i go abt extracting the integer from my variable? PLs help!
I am who you think I am
|
|
|
|
|
Just type:
"WHERE = %d", fileid;
or something like this.
This might work.
|
|
|
|