Originally posted by: Ricardo Yiu
I am a new user to SQL. May I ask how to get value of each field in each record after executing an select sql statement?
For example, if I have two fields: EmployeeID & Salary.
if( SQLDirect.ExecuteSQL( "SELECT * FROM Employee" ==SQL_SUCCESS ) {
Many thanks!!!
Dear All,
How should I make the coding by using this useful class in the following codes.
CSQLDirect SQLDirect( "Company" );
while( SQLDirect.Fetch()==SQL_SUCCESS ) {
.
???
.
}
}
Could somebody give me a sample?
Ricardo
Originally posted by: Victor Vat
Very good class!
But I want to use scrollable cursor.
Fetch in your class using SQLFetch,
but I want to use SQLFetchScroll.
How I must do it, how I must set attributes
for this ..?
Originally posted by: fengj
How can i delete a record in a table of
Access97 through the condition of time?
I used the sentence like this :
delete statistics47 where begintime = '3-05-99 15:45:12',it can work for sybase,but it doesnot work in Access.
and the Access cues :22005
[Microsoft][ODBC Microsoft Access 97 Driver] Data type mismatch in criteria expression.i tried many times for every format of time ,but all failed.
How can i do?
Who can help me?
Originally posted by: Hoon Suk
It's so cool!!!
simple and work well.
It's a tip for the vc beginner.
you must add '#include <afxdb.h> in StdAfx.h file
Do fun develope...
Originally posted by: Andy G
My contribution: I needed to find the tables available in the database, here's an additional function to
do it:
bool CSQLDirect::GetTableNames(CStringList& slTabs)
SQLCHAR scName[129];
// Allocate a handle, v3.5 compliant
SQLRETURN rc = SQLAllocHandle(SQL_HANDLE_STMT, m_hDBC, &handle);
if (rc == SQL_SUCCESS)
if (rc == SQL_SUCCESS)
rc = SQLBindCol(handle, 3, SQL_C_CHAR, (SQLPOINTER)
// Get all the table names
while (rc != SQL_NO_DATA)
// Free the handle
if (handle != NULL)
return (rc == SQL_NO_DATA); // Completed ok?
Andy
Thanks for your work!
Making the underlying ODBC classes work simply is not an easy task.. so I like your wrapper class. Keep
it simple!
The only slight worry is that some of the code may not be v3.5 compliant - easily fixed.
{
// Gets the table names in the database. SQLTables is expensive
// so return all the results now in a list of strings
SQLHANDLE handle;
{
rc = SQLTables(handle, NULL, 0, NULL, 0,
(SQLCHAR *) "%", SQL_NTS, (SQLCHAR *) "TABLES", 6);
{
// Bind the table name to the variable
&scName, sizeof(scName), NULL);
{
rc = SQLFetch(handle);
if (rc != SQL_NO_DATA)
slTabs.AddTail(CString(scName));
}
}
SQLFreeHandle(SQL_HANDLE_STMT, handle);
}
}
Originally posted by: George
Hi,
Great but...be careful for the GetParent() function, it MIGHT return NULL to indicate an error, and then you will jump-out-of-the-NULL pointer, which ends up as an access violation and the application is DEAD... It must be checked before use the pointer. Assertion is not enougth as well.
Best Regards.
ReplyOriginally posted by: Mike McCarty
Nice class! How about a constructor that accepts an HDBC, so that an existing CDatabase connection can be used ?.
ReplyOriginally posted by: Peter Gutwein
First i have to thank for this source code.
In my project i have to connect with UserID and Password, so i changed the function Connect(CString) a
bit. If anyone needs the sourcecode
contact me. Later i will give a sample.
Originally posted by: Ian Bishrey
I like this class - it has saved me from creating about a million CRecordSets so far. However, I now need to insert non-pritable stuff (e.g. CR/LF) into my database; I've been using CSQLDirect's ExecuteSQL to execute an SQL INSERT command and this works fine ... until I need to insert a control character or single quote. I've looked all over the 'net for advice on this without much luck. I know that you can escape character literals in PostgreSQL by using \xHH (HH is a hex code), but I don't think this is a standard. So, my question is:
o Is there a standard means of escaping non-printable literals in SQL INSERT commands?
o Could support for this feature be added to CSQLDirect?
TIA
Ian
ReplyOriginally posted by: Stephen Perry
What I'd like to know is how to use your methods to bind specific
Master_Table
Slave_Table
and want to use this SQL statement to retrieve data from them:
SELECT MT_ID, MT_TYPE, MT_DATE1, MT_DATE2, MT_CNT, ST_DATE, ST_SIGN, ST_CODE, ST_COMMENT
one record at a time (for the obvious use of making a form to edit
My current code uses
I have only been using VC++ 6.0 and MFC for about a month now, so please
Thank you.
First off, kudos on a great programming idea.
database columns from multiple tables in the same database to variables
used for display/editing on a form. For example, if I have two tables
with this layout:
----------------
MT_ID C(11) // my notation for an 11 character string
MT_TYPE C(2)
MT_DATE1 date // oracle date field
MT_DATE2 date
MT_CNT I(5) // my notation for an integer with a max of 5 digits
----------------
ST_ID C(11)
ST_DATE date
ST_SIGN C(5)
ST_CODE C(3)
ST_COMMENT C(1500)
FROM Master_Table, Slave_Table
WHERE MT_ID = ST_ID
AND MT_TYPE != 'CLOSED'
AND MT_DATE2 <= sysdate
records and be able to scroll through them sequentially).
SELECT <blah>
INTO <blech>
FROM tbl
WHERE <whatever>
as a method for extracting data from the database into my local vars.
Unfortunately, there is no MFC (or other that I know of) way to do this.
And having to make a separate CRecordset for each table used on each
form is not a viable solution. (That's what I was told to do by the
nice people at MSN.COM.)
be gentle in your replies.