|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
I want to store file's data into data base using MFCIam a new bird into this forest, so plz help me Iam given a task to accept file name from user (I did using CFileDialog class,Open dialog) now store this files data into MSSQL DB The structure of table is Files (FileID IDENTITY(1,1),FileData text,......) as u might be knowing text is a blob the other blobs are ntext & image, tell me if I am using the wrong one. I used CDatabase & CRecordset class after accepting the filename Iam opening it Usin CFile::Open method reading it into a TCHAR buffer now tell me whether to use TCHAR buffer or CString (remember that the file could be txt,doc,exe,mdb,wmv,mov any) if CString or any thing other (CByteArray,CLongBinary etc) then how to use that. My code for reading file is as follows CFile objFilePtr; CFileException objFileException; CMyIdeaCommunicatorApp* pApp = static_cast<CMyIdeaCommunicatorApp*>(AfxGetApp()); if ( !objFilePtr.Open(objFileItemInfo->m_strFileName,CFile::modeRead, &objFileException ) ) { TRACE( "Can't open file %s, error = %u.\n", objFileItemInfo->m_strFileName, objFileException.m_cause ); } objFilePtr.SeekToBegin(); MFC_SEH_TRY { //Files--FileData objFilePtr.Read(objFileItemInfo->m_szFileData, sizeof(objFileItemInfo->m_szFileData)); //int nLen = sizeof(objFileItemInfo->m_szFileData) / sizeof(TCHAR); int nLen = FindLength(objFileItemInfo->m_szFileData); } MFC_SEH_CATCH() following is the code to insert into Files table strSQL.LoadString(AfxGetInstanceHandle(),IDS_SQL_INSERT_INTO_FILES); str = strSQL; int nFileSize = (int) objFileItemInfo->m_nFileSize; strSQL.Format(str, InsertQuote(objFileItemInfo->m_strFileName), InsertQuote(objFileItemInfo->m_szFileData), InsertQuote(objFileItemInfo->m_strComment), nFileSize, nVoiceMemoID, objFileItemInfo->m_strAuthor, InsertQuote(objFileItemInfo->m_strTitle)); m_pDataBase->ExecuteSQL(strSQL); Please tell me what to do or if any one is having code ready for the same purpose, any one have done this before please give me suggestion. The MORAL of the Story is to store different files (their data) into DB & to read them back OK waiting for ur reply Bye |
|||||||||||||||||||||||