473,486 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to write a string from a database into a xml file?

61 New Member
Hai,

i'm having a string in a specific field of a database...

now i want to retrive that string from the database
and i have to write that string into a xml file....

retriving is not a problem for me...

but how can i write that string to a xml file....

ie i have to write that string to a file which is to be saved as
xml file...

is there any writeFile method available for doing this
process..

Or is there any source codes available in the net?

I'm a beginner to C++....

Can any one plzz explain me....

thanks..
senthil
Dec 28 '06 #1
8 2513
r035198x
13,262 MVP
Hai,

i'm having a string in a specific field of a database...

now i want to retrive that string from the database
and i have to write that string into a xml file....

retriving is not a problem for me...

but how can i write that string to a xml file....

ie i have to write that string to a file which is to be saved as
xml file...

is there any writeFile method available for doing this
process..

Or is there any source codes available in the net?

I'm a beginner to C++....

Can any one plzz explain me....

thanks..
senthil
Did you manage to get it to work when you tried ithere?
Dec 28 '06 #2
asenthil
61 New Member
Hai r035198x
ur conditions worked supervly
when i used for writing a string into a file...

But when i tried to writed the string which is fetched from the database
it is not working....

But anyway i will do the second step surely....

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

But ur codings gave me an idea to write a file...

Hereafter i will do my work well...

thanks for ur support
senthil
Dec 29 '06 #3
r035198x
13,262 MVP
Hai r035198x
ur conditions worked supervly
when i used for writing a string into a file...

But when i tried to writed the string which is fetched from the database
it is not working....

But anyway i will do the second step surely....

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

But ur codings gave me an idea to write a file...

Hereafter i will do my work well...

thanks for ur support
senthil
You need to explain how it's not working then so that people know how to help. Is the xml file being created at all?
Dec 29 '06 #4
asenthil
61 New Member
Hai
i am senthil...

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

I'm trying to retrive a string from the database and write it to a xml file...

i tried to write a string into a xml file...

But dont know how to retrive a string from the database and write it to a xml

file...

i tried the following codings for the above process..

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include <mysql.h> 
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include<string.h>
  6.  
  7. #define host "192.168.0.2"
  8. #define username "root" 
  9. #define password "" 
  10. #define database "senthil"
  11.  
  12. void main()
  13. {
  14.     MYSQL *conn; 
  15.     conn = mysql_init(NULL);
  16.     mysql_real_connect(conn,host,username,password,database,0,NULL,0); 
  17.     MYSQL_RES *res_set; 
  18.     MYSQL_ROW row;        
  19.     unsigned int i=0; 
  20.     unsigned int j=0;        
  21.     mysql_query(conn,"SELECT * FROM sen1");
  22.     res_set = mysql_store_result(conn);
  23.     unsigned int numrows = mysql_num_rows(res_set);   
  24.    while ((row = mysql_fetch_row(res_set)) != NULL)
  25.      {
  26.                   HANDLE hFile; 
  27.                   DWORD wmWritten; 
  28.       char *strData =row[0];
  29.         hFile = CreateFile("C:\\test.xml",GENERIC_READ|GENERIC_WRITE, 
  30. FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); 
  31.        WriteFile(hFile,strData,(DWORD)(sizeof(strData)),&wmWritten,NULL); 
  32.        CloseHandle(hFile);                                   
  33.         }
  34.            mysql_close(conn);       
  35.            getch();
  36. }    
Here row[0] contains the string...

and i want to write it into the test.xml file...

Can any one plzz tell me how to retrive a string from the database
and write it to a file?

senthil
Dec 29 '06 #5
asenthil
61 New Member
Hai r035198x,

i explained in another post in c,c++ help with the codings i had developed for wrinting
a string to a xml file...

Plzz see that post and tell me...

thanks..
senthil
Dec 29 '06 #6
r035198x
13,262 MVP
Hai
i am senthil...

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

I'm trying to retrive a string from the database and write it to a xml file...

i tried to write a string into a xml file...

But dont know how to retrive a string from the database and write it to a xml

file...

i tried the following codings for the above process..

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include <mysql.h> 
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include<string.h>
  6.  
  7. #define host "192.168.0.2"
  8. #define username "root" 
  9. #define password "" 
  10. #define database "senthil"
  11.  
  12. void main()
  13. {
  14. MYSQL *conn; 
  15. conn = mysql_init(NULL);
  16. mysql_real_connect(conn,host,username,password,database,0,NULL,0); 
  17. MYSQL_RES *res_set; 
  18. MYSQL_ROW row;     
  19. unsigned int i=0; 
  20. unsigned int j=0;     
  21. mysql_query(conn,"SELECT * FROM sen1");
  22. res_set = mysql_store_result(conn);
  23. unsigned int numrows = mysql_num_rows(res_set); 
  24. while ((row = mysql_fetch_row(res_set)) != NULL)
  25. {
  26. HANDLE hFile; 
  27. DWORD wmWritten; 
  28.      char *strData =row[0];
  29. hFile = CreateFile("C:\\test.xml",GENERIC_READ|GENERIC_WRITE, 
  30. FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); 
  31. WriteFile(hFile,strData,(DWORD)(sizeof(strData)),&wmWritten,NULL); 
  32. CloseHandle(hFile);          
  33.         }
  34. mysql_close(conn);     
  35.      getch();
  36. }    
Here row[0] contains the string...

and i want to write it into the test.xml file...

Can any one plzz tell me how to retrive a string from the database
and write it to a file?

senthil
In the above code from what I can see you are creating the file in a while loop. This is will create as many files as the data is retrieved from the database. You should create the file once outside the while loop maybe as the first step of the main method.
Dec 29 '06 #7
asenthil
61 New Member
Ya ok, what u r saying true....

But in the above program i'm using a database which is having

only one row...
plzz alter the program for writing to a text file...

Expand|Select|Wrap|Line Numbers
  1. that is my database like this...
  2. ---------------
  3. string (header)
  4. -------------------
  5.  
  6. senthil (row[0])
here only one row. when there is multiple rows it will create multiple files..

But here only one row contains a string senthil so it will create only one file..

In the output(for writing to a text file) The above program creates a text file
and writes the string... But when i opened that text file

it writes only the first four letters (sent)- this string is stored in the text file...

what shall i do for to store the full string...

will u plzz explain me...

thanks
senthil
Dec 29 '06 #8
r035198x
13,262 MVP
Ya ok, what u r saying true....

But in the above program i'm using a database which is having

only one row...
plzz alter the program for writing to a text file...

Expand|Select|Wrap|Line Numbers
  1. that is my database like this...
  2. ---------------
  3. string (header)
  4. -------------------
  5.  
  6. senthil (row[0])
here only one row. when there is multiple rows it will create multiple files..

But here only one row contains a string senthil so it will create only one file..

In the output(for writing to a text file) The above program creates a text file
and writes the string... But when i opened that text file

it writes only the first four letters (sent)- this string is stored in the text file...

what shall i do for to store the full string...

will u plzz explain me...

thanks
senthil
Can you put print statements to print
strData and
(DWORD)(sizeof(strData))

before writting to the file so that we know the values that they are holding.

If you are going to create an XML file you might want to include < > symbols
Dec 29 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3035
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
4
2912
by: JDJones | last post by:
I'm trying to write a script that will read from a text list of songs that I burned onto my CD (Albums011.txt), then write to the database text the new text made ready for inserting into a...
0
3024
by: Peter Horwood | last post by:
I am having trouble writing an XML file out on my localhost development machine. I get: Server Error in '/ProblemSolved' Application. -----------------------------------------------------------...
3
17939
by: john | last post by:
I need to produce a RTF-document which is filled with data from a database. I've created a RTF-document in WordPad (a template, so to speak) which contains 'placeholders', for example '<dd01>',...
3
1159
by: belange | last post by:
I try to create a little web application with c# and visual studio.net. With this application, a student can reserved a computer station, the day and the hour. I want to write these informations in...
5
3634
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
2
2893
by: Alan T | last post by:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="DataBaseConnection" connectionString="server=localhost;database=SalesDB;User
9
2832
by: asenthil | last post by:
Hai to all,, i had to tried to retrive and write a single row to a file from the database.. But dont know to write all the retrived rows to a file from the database.. how to do that... ...
1
1772
Krantor
by: Krantor | last post by:
Hi all, i am quite new to c# and was wondering if i could get assistance on an issue im having with writing a binary file from the database to my local machine, this is the code i have: string...
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.