C++ and query

This is a discussion on C++ and query within the C++ Programming forums, part of the General Programming Boards category; Hello all, well is there some logical error in my code: Well in the database I have 5 fields clearly ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    37

    C++ and query

    Hello all,
    well is there some logical error in my code:
    Well in the database I have 5 fields clearly labelled in the 3rd line of this code,
    but when I run it, the complier (C++ Borland 6.0 enterprise edition) generates an error telling me that there is syntax error in INSERT INTO , but where?????????????
    can anybody help
    thanks
    the code is:

    Form1->ADOQuery1->SQL->Clear();
    Form1->ADOQuery1->SQL->Add("Insert Into faxSent");
    Form1->ADOQuery1->SQL->Add("(Date, ToPerson, ToHotel, FaxNo, msg)");
    Form1->ADOQuery1->SQL->Add(" values (ate, :To, :Hotel, :faxno, :msg)");
    Form1->ADOQuery1->Parameters->ParamByName("Date")->Value = DateBox->Text;
    Form1->ADOQuery1->Parameters->ParamByName("To")->Value = ToBox->Text;
    Form1->ADOQuery1->Parameters->ParamByName("Hotel")->Value = HotelBox->Text;
    Form1->ADOQuery1->Parameters->ParamByName("faxno")->Value = FaxBox->Text;
    Form1->ADOQuery1->Parameters->ParamByName("msg")->Value = msgBox->Text;
    Form1->ADOQuery1->ExecSQL();
    Form1->ADOQuery1->Parameters->Clear();

  2. #2
    Registered User
    Join Date
    May 2006
    Location
    Berkshire, UK
    Posts
    29
    I am not familiar with your version of C++, nor the SQL for that matter but, do you need a space after the "faxSent"? The "f" is meant to be lower case isn't it? Can you print out the SQL to the screen before executing it? Try that and put it through as a command-line query (I presume you have a command-line client).

    Fairly general suggestions I know...

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    37
    wel, I dont think that I need a space after the faxSent and the name for the table is correct
    what do u mean by printin out the SQL to the screen before executing it,
    I am wirting the code inside the C++ Builder, since I am using the ADO connection.............

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Code:
    DateBox->Text;
    If the DATE column in your FAXSENT table is of type DATE then this will cause an error since you are getting text (I am guessing) from your DateBox object and inserting it into a date field. You might need to add in a TO_DATE() call to format the text from this DateBox into a proper DATE type.

    Code:
    Form1->ADOQuery1->SQL->Clear();
    Form1->ADOQuery1->SQL->Add("Insert Into faxSent");
    Form1->ADOQuery1->SQL->Add("(Date, ToPerson, ToHotel, FaxNo, msg)");
    Form1->ADOQuery1->SQL->Add(" values( to_date(:Date,'YYYYMMDD'), :To, :Hotel, :faxno, :msg)");
    Form1->ADOQuery1->Parameters->ParamByName("Date")->Value = DateBox->Text;
    Form1->ADOQuery1->Parameters->ParamByName("To")->Value = ToBox->Text;
    Form1->ADOQuery1->Parameters->ParamByName("Hotel")->Value = HotelBox->Text;
    Form1->ADOQuery1->Parameters->ParamByName("faxno")->Value = FaxBox->Text;
    Form1->ADOQuery1->Parameters->ParamByName("msg")->Value = msgBox->Text;
    Form1->ADOQuery1->ExecSQL();
    Form1->ADOQuery1->Parameters->Clear();
    Replace 'YYYYMMDD' with whatever matches the expected format of the text, i.e. if DateBox->Text is "10-MAR-2006" then you would want to use 'DD-MON-YYYY' instead. If the text entered into this DateBox object isn't standardized in some way then this becomes more complicated.

    Anyway, that's my guess as to what might be happening.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    37
    well I have changed the type of the date and make it as text, also the same error is also occuring, now all the fields are text...............

Popular pages Recent additions subscribe to a feed

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