Thread: mysql++ select * from table where such = '?'

  1. #1
    Registered User juschillin's Avatar
    Join Date
    Sep 2002

    mysql++ select * from table where such = '?'

    I'm still new so please be nice

    case IDC_SEARCH:
    					BOOL bSuccess;
    					int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_SEARCHFIELD));
    						if(len > 0)
    							// Now we allocate, and get the string into our buffer
    							int i;
    							char* buf;
    							buf = (char*)GlobalAlloc(GPTR, len + 1);
    							GetDlgItemText(hwnd, IDC_SEARCHFIELD, buf, len + 1);
    								int index = SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)buf);
    					MYSQL *pConnection; 
    					MYSQL_RES *pResult;   //pointer to the result set structure
    					MYSQL_ROW Row;
    					pConnection = mysql_init(NULL);
    					SendDlgItemMessage(hwnd, IDC_SHOWCOUNT, LB_ADDSTRING, 0, (LPARAM)TEXT("Attempting to Connect to Database...."));
    					//SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Attempting to Connect to"));
    					//SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Database......."));
    					mysql_real_connect(pConnection, "localhost", "username","password","database",0,NULL,0);
        				SetDlgItemText(hwnd, IDC_SHOWCOUNT, "Attempting To Connect To Database....");
    					mysql_query(pConnection,"SELECT * FROM products"); //query the database
    					pResult = mysql_store_result(pConnection); 
    					TCHAR szBuffer[50];
    					wsprintf (szBuffer, TEXT ("%d"), mysql_num_rows (pResult));
    					SetDlgItemText(hwnd, IDC_SHOWCOUNT, "Connected....Please Wait!");
    					while ((Row = mysql_fetch_row(pResult)))
    						TCHAR szProducts[100];
    						wsprintf(szProducts, "%s.....%s.....%s.....%s....%s", Row[1], Row[4], Row[5], Row[7], Row[9]);
    						SendDlgItemMessage (hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)szProducts);
    					SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Total # of Products In Database:"));
    					SendDlgItemMessage (hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)szBuffer);
    					//printf("\n\nThe Number Of products in the database: %d\n\n",mysql_num_rows(pResult));
    					SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("______________________"));
    					SetDlgItemText(hwnd, IDC_SHOWCOUNT, "Done");
    							// Dont' forget to free the memory!
    This is the part I'm having a problem with:

    mysql_query(pConnection,"SELECT * FROM products");

    I want to do:

    mysql_query(pConnection,"SELECT * FROM products where itemN = 'itemnumber'");

    but replacing 'itemnumber' with the text from IDC_SEARCHFIELD

    What I am basically wanting to do is....I have a text box (IDC_SEARCHFIELD) and when i click on search take the text in the IDC_SEARCHFIELD and query mysql for a match and print the results in a list box(IDC_LIST).

    using the buffer (buf*) I am able to print the text I entered but I'm not sure how to query the database i have tried the following but not sure what I'm doing wrong

    mysql_query(pConnection,"SELECT * FROM products where itemN = 'buf'");

    I know this isn't a mysql board but thanks for the help anyway.
    !Carpe Diem!
    "Sieze the Day"

  2. #2
    Registered User juschillin's Avatar
    Join Date
    Sep 2002
    Does anybody know anything about MySQL?


    Does anybody know where I can get help that makes sense....NOT the MySQL manual!

    Thanks for your help,

    !Carpe Diem!
    "Sieze the Day"

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    //assumes you already got the text from that field and put it in a var called "szEditText"
    char sqlString[256];
    strcpy(sqlString,"SELECT * FROM products where itemN = \\'");
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  2. mysql select statement
    By Stabbsy in forum C Programming
    Replies: 3
    Last Post: 08-17-2007, 11:06 AM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM