GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Jan-2007, 21:10
asenthil asenthil is offline
New Member
 
Join Date: Dec 2006
Posts: 24
asenthil is on a distinguished road

How to Write a string which is retrived from a database into a file?


Hai to all...

Wish U All a Happy New Year...

this is senthil...

i'm now working in the field of VC++....

i had tried to write a simple string into a file(any file such as xml,txt
or html)....

if we put .txt.. then the file automatically saving as txt..

But i dont know how to retrive a string from the Mysql database and
write that retrived string to a file

My codings are below...
CPP / C++ / C Code:
#include<stdio.h>
#include <mysql.h>
#include <conio.h>
#include <windows.h>
#include<string.h>

#define host "192.168.0.2"
#define username "root"
#define password ""
#define database "indesign"

void main()
{

        MYSQL *conn;
        conn = mysql_init(NULL);

        mysql_real_connect(conn,host,username,password,database,0,NULL,0);
        MYSQL_RES *res_set;

        MYSQL_ROW row;

        mysql_query(conn,"SELECT text FROM sen1");
        res_set = mysql_store_result(conn);
        unsigned int numrows = mysql_num_rows(res_set);

       
       [b]//For Creating a file[/b]     
      HANDLE hFile;
       DWORD wmWritten;
       char *strData[] = row[0];
       hFile = CreateFile("C:\\test2.txt",GENERIC_READ|GENERIC_WRITE,
       FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

        while ((row = mysql_fetch_row(res_set)) != NULL)
    {

       
       WriteFile(hFile,strData,(DWORD)(sizeof(strData)),&wmWritten,NULL);
       CloseHandle(hFile);
    }
           mysql_close(conn);
           getch();

        }


in row[0] i just put a string "senthil"...

But if there is no db connectivity the above program works
supervly... it creates xml, html, txt any type of files.

Now just i'm writing that string "senthil" which is retrived from the database
to a text file...

But it is not working..

My database is like this
--------
text
--------
senthil

i'm just trying to retrive the above string(senthil)...

when i run the above program, a text file created and the
first four letters of the string (sent) wrote into the text file...
the remaining letters were not written...

if there is any string in the database only the first four letters
will be written...

Can any one help me...

i'm a beginner to C++ concepts..

What shall i do for this?

thanks
senthil..
Last edited by LuciWiz : 02-Jan-2007 at 13:06. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CD Burner Help - Power Calibration Error.... JonBoy420 Computer Hardware Forum 111 19-Feb-2009 03:54
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
Help wit my source code compiler errors Krandygrl00 C++ Forum 1 06-Jun-2005 08:14
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:38.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.