mysql database to listbox

This is a discussion on mysql database to listbox within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I'm trying to output my database to a listbox... Code: MYSQL *conn; MYSQL_RES *result; MYSQL_ROW row; void Mysql_Server_Connect( HWND ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    mysql database to listbox

    Hello, I'm trying to output my database to a listbox...

    Code:
    MYSQL	*conn;
    MYSQL_RES  *result;		
    MYSQL_ROW  row;			
    
    
    void Mysql_Server_Connect( HWND hWnd ) 
    {	
    // create list box: to display database.																			
    HWND hWnd_List1 = CreateWindow( TEXT("LISTBOX"), NULL, WS_CHILD|WS_VSCROLL|LBS_DISABLENOSCROLL|WS_VISIBLE|LBS_STANDARD, 360, 165, 290,290, hWnd, NULL, ghInstance, NULL);
    
    conn = mysql_init(NULL);
    
    mysql_real_connect(conn, "localhost", "root", "password", "mydatabase", 0, NULL, 0) ;
    	
    mysql_query(conn, "SELECT * FROM drivers");
    result = mysql_store_result(conn);	
    
    TCHAR Buffer [50];
    		 
    for (unsigned int i=0; i< mysql_num_rows(result); i++) 
       {
            while( row = mysql_fetch_row(result) )
            {	
    	for (unsigned int k=0; k< mysql_num_fields(result); k++)
    	{
    	//unsigned long * lengths = mysql_fetch_lengths(result);
    	//wsprintf (Buffer, TEXT ("%lu"), lengths[k]);
    	//(const char*)SendMessage(hWnd_List1,  LB_INSERTSTRING, 0,
                      (LPARAM)Buffer );
    
    	 wsprintf (Buffer, TEXT ("%s"), row[k]);
    	(const char*)SendMessage(hWnd_List1,  LB_INSERTSTRING, 0,  
                     (LPARAM)Buffer );
    	}
                }
          }
    		
    
    mysql_free_result(result);
    mysql_close(conn);  
    }
    '%s'' doesn't seem to work,
    what should I use here?

    Thank you.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    Either sprintf()
    Or TEXT("%S") - NOTE CAPITAL

    It depends on whether you're using sprintf or wsprintf, and/or have UNICODE defined.
    printf Type Field Characters (CRT)
    wsprintf Function (Windows)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    Talking

    Hi Salem,

    TEXT("%S") works!!!

    Thank you !

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I would be worried about buffer over-runs with the buffer of only 49 chars (unless I knew all the DB fields had been limited to less than 50 characters).

    [the sprintf() functions insert a null terminator at the end of the string, so require one more char in buffer space than the biggest DB field can hold (or use a 'safe' version like _snprintf() if you can).]
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to connect borland c++ with mysql database
    By hdhd in forum C++ Programming
    Replies: 1
    Last Post: 02-11-2010, 02:34 PM
  2. [C#] MySQl database problems
    By Jelte in forum C# Programming
    Replies: 5
    Last Post: 09-26-2008, 03:11 AM
  3. Problem connecting to MySQL Database?
    By MrLucky in forum C++ Programming
    Replies: 5
    Last Post: 01-30-2006, 10:30 AM
  4. About C++ and MySQL or oether free database
    By xxxrugby in forum C++ Programming
    Replies: 18
    Last Post: 12-30-2005, 05:28 AM
  5. Can i use the ASP to access MYSQL database??
    By Frankiepoon in forum Windows Programming
    Replies: 1
    Last Post: 10-15-2002, 02:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21