Click here to Skip to main content
15,890,557 members
Home / Discussions / Database
   

Database

 
QuestionRevoking Oracle Roles and Privileges Pin
Muammar©2-Mar-09 23:21
Muammar©2-Mar-09 23:21 
AnswerRe: Revoking Oracle Roles and Privileges Pin
scottgp3-Mar-09 0:27
professionalscottgp3-Mar-09 0:27 
QuestionConnecting to a SQL database programmatically Pin
Richard Blythe2-Mar-09 17:25
Richard Blythe2-Mar-09 17:25 
AnswerRe: Connecting to a SQL database programmatically Pin
Rupesh Kumar Swami2-Mar-09 19:10
Rupesh Kumar Swami2-Mar-09 19:10 
AnswerRe: Connecting to a SQL database programmatically Pin
Eddy Vluggen3-Mar-09 4:38
professionalEddy Vluggen3-Mar-09 4:38 
QuestionLogging both text and numbers Pin
User 127822-Mar-09 17:01
User 127822-Mar-09 17:01 
AnswerRe: Logging both text and numbers Pin
Eddy Vluggen3-Mar-09 4:41
professionalEddy Vluggen3-Mar-09 4:41 
QuestionVC++ 6 and excel cant read anything other than text formatted cell Pin
RDEPTYLTD2-Mar-09 12:03
RDEPTYLTD2-Mar-09 12:03 
Visual C++ and Microsoft Excel 97 ~ 2003

I am working on a project at the moment and have an issue with reading MS Excel 97 ~ 2003 spreadsheets.

My problem relates to the Excel field format of any given field in the spreadsheet, if a field is formatted in Excel to anything other than Text, then I cannot read the data from that field. for example if column A1 is formatted in excel to Text (good data returned) if A2 is formated to a number (a null is returned) if A3 is text (good data is returned), and so on.

The problem seems to be getting my code to understand the format of any particular field, Here is a snipped of my code;


1) I am using the CRecordset class to open and read the Excel spreadsheet. The spreadsheet has
defined name ranges and generally all works just fine (Provided the fields are text formatted).

2)If i use this line of code to first attempt to read what type of data is in a NUMBER field
"recset.GetODBCFieldInfo( m_csaColumnNames.GetAt(i), fieldinfo );"
I get a positive response when i try the different data types
"if(fieldinfo.m_nSQLType == SQL_VARCHAR){AfxMessageBox("SQL_VARCHAR");}"
suggesting its a data type SQL_VARCHAR data type

3) If i then call GetFieldValue to get the info from a field with a switch command

CDBVariant variant;

recset.GetFieldValue( m_csaColumnNames.GetAt(i), variant);

switch(variant.m_dwType)
{
case DBVT_SHORT:{ szValue.Format("%d", variant.m_iVal);
break;
}
case DBVT_LONG:{ szValue.Format("%d", variant.m_lVal);
break;
}
case DBVT_SINGLE:{ if ( variant.m_fltVal == 0.0 )
szValue = "Verify";
else
szValue.Format("%.1f", variant.m_fltVal);
break;
}

case DBVT_DOUBLE:{ if ( variant.m_dblVal == 0.0 )
szValue = "Verify";
else
szValue.Format("%.1f", variant.m_dblVal);
break;
}

case DBVT_DATE:{
szValue.Format("%B %d, %Y",variant.m_pdate );
break;
}

case DBVT_STRING:{ szValue = *variant.m_pstring; //szValue = V_BSTRT( &varValue );//convert BSTR to CString
break;
}

case DBVT_BOOL:{ if(variant.m_boolVal)
szValue = "TRUE";
else
szValue = "FALSE";
break;
}

case DBVT_UCHAR:{ szValue = (char*)variant.m_chVal;
break;
}

case DBVT_NULL:{
szValue = "Error Null"; AfxMessageBox(szValue);
break;
}
default:{
szValue = "\0";
break;
}
}//switch


RESULTS
All fields which are text, return a valid value which is exactly as per the Excel Spreadsheet, all fields which contains numbers or I even tried date formats in excel return DBVT_NULL which is totally useless because the cell has a number in it or a date.

SUMMARY
I have tried to read the data using GetODBCFieldInfo only and then calling the m_ member depending on the type returned which i know to be in the field, but that does not give me anything other than an unsigned short with random values that bear no resemblance to what is in the actual field.


Any help that anyone can offer in regards to solving this problem would be much appreciated and I I can get the entire class working properly I have happy to post it here for all to use.

Thanks in advance for any assistance.
QuestionGetting TableName in DataSet/DataTable from SP Pin
Maxim Langman2-Mar-09 11:21
Maxim Langman2-Mar-09 11:21 
AnswerRe: Getting TableName in DataSet/DataTable from SP Pin
ya3mro10-Nov-09 20:26
ya3mro10-Nov-09 20:26 
AnswerRe: Getting TableName in DataSet/DataTable from SP Pin
sharad487-Dec-09 20:46
sharad487-Dec-09 20:46 
GeneralRe: Getting TableName in DataSet/DataTable from SP Pin
Maxim Langman9-Dec-09 19:34
Maxim Langman9-Dec-09 19:34 
QuestionA Query Pin
mehrdadc481-Mar-09 23:44
mehrdadc481-Mar-09 23:44 
AnswerRe: A Query Pin
Rupesh Kumar Swami1-Mar-09 23:56
Rupesh Kumar Swami1-Mar-09 23:56 
GeneralRe: A Query Pin
mehrdadc482-Mar-09 0:03
mehrdadc482-Mar-09 0:03 
GeneralRe: A Query Pin
Rupesh Kumar Swami2-Mar-09 0:45
Rupesh Kumar Swami2-Mar-09 0:45 
GeneralRe: A Query Pin
Abhishek Sur2-Mar-09 4:27
professionalAbhishek Sur2-Mar-09 4:27 
GeneralRe: A Query Pin
mehrdadc482-Mar-09 4:42
mehrdadc482-Mar-09 4:42 
Questionsql query Pin
Zeyad Jalil1-Mar-09 22:59
professionalZeyad Jalil1-Mar-09 22:59 
AnswerRe: sql query Pin
Vimalsoft(Pty) Ltd1-Mar-09 23:10
professionalVimalsoft(Pty) Ltd1-Mar-09 23:10 
QuestionForeign Key Pin
Zeyad Jalil1-Mar-09 21:06
professionalZeyad Jalil1-Mar-09 21:06 
AnswerRe: Foreign Key Pin
goodideadave2-Mar-09 7:48
goodideadave2-Mar-09 7:48 
AnswerRe: Foreign Key Pin
Dipak Rade3-Mar-09 0:36
Dipak Rade3-Mar-09 0:36 
QuestionError: 18056, Severity: 20, State: 23. Pin
poonam kwatra1-Mar-09 18:43
poonam kwatra1-Mar-09 18:43 
QuestionConditional Execute If... Execute Pin
swjam1-Mar-09 15:16
swjam1-Mar-09 15:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.