If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Syntax error in INSERT INTO statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 05-09-07, 09:07
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Why are there apostrophes surounding 2008 and not the other 3 values?
__________________
George
Twitter | Blog
Reply With Quote
  #17 (permalink)  
Old 05-09-07, 10:10
StarStriker StarStriker is offline
Registered User
 
Join Date: May 2007
Posts: 11
2008 is a hard coded value not taken from a table as its always the same throughout
Reply With Quote
  #18 (permalink)  
Old 05-10-07, 06:28
StarStriker StarStriker is offline
Registered User
 
Join Date: May 2007
Posts: 11
after 3 days of grafting ive managed to get the thing to work

if anyone is interested its as below:

procedure TfrmChooseOptions.DBGAvailableModulesDblClick(Send er: TObject);
var
sql: string;
AcadYear: string;
begin
AcadYear := '2008';
sql := 'INSERT INTO StudentOptionChoices ( StudentID, ModuleCode, semester, Academic_Year ) ' ;
sql := sql + ' VALUES (' + quotedstr(DBGStudentsList.datasource.dataset.Field ByName('studentID').AsString);
sql := sql + ', ' + quotedstr(DBGAvailableModules.datasource.dataset.F ieldByName('ModuleCode').AsString);
sql := sql + ', ' + DBGAvailableModules.datasource.dataset.FieldbyName ('semester').AsString;
sql := sql + ', ' + quotedstr(AcadYear) + ')' ;

DMStudentRecord.ADOCMOptionsChoices.CommandText := sql;
try
DMStudentRecord.ADOCMOptionsChoices.Execute;
RefreshDataChoices;
except
on E: Exception do showmessage( 'You have already added that module'); //E.Message);


the try/except statement does not allow duplicate data in the grid the double click moves it to


now to make a delete function work...

which is on the lines of:

sql := 'DELETE FROM StudentOptionsChoices ( StudentID, ModuleCode, semester, Academic_Year ) ' ;
sql := sql + ' WHERE studentID = ' + quotedstr(DBGStudentsList.datasource.dataset.Field byName('studentID').asstring);
sql := sql + ' AND ModuleCode = ' + quotedstr(DBGAvailableModules.datasource.dataset.F ieldByName('ModuleCode').AsString);
sql := sql + ' AND semester = ' + (DBGAvailableModules.datasource.dataset.FieldbyNam e('semester').AsString);
sql := sql + ' AND AcadYear = ' + quotedstr(AcadYear) + ')' ;

DMStudentRecord.ADOCMOptionsChoices.CommandText := sql;
try
DMStudentRecord.ADOCMOptionsChoices.Execute;
RefreshDataChosen;
finally
end;

or something like it...


thanks for all you help folks. feel free to post if youve any extra advice that may help

Alex
Reply With Quote
  #19 (permalink)  
Old 05-10-07, 06:37
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
So quotedstr was the little trick that we all missed?
I guess that seems fairly obvious now
Congrats on getting a working solution!

As for your delete; if you simply want to delete the row of data where the criteria matches then:
Code:
sql := 'DELETE FROM StudentOptionsChoices ' ;
sql := sql + ' WHERE ....
HTH -GeorgeV
__________________
George
Twitter | Blog
Reply With Quote
  #20 (permalink)  
Old 05-10-07, 16:39
StarStriker StarStriker is offline
Registered User
 
Join Date: May 2007
Posts: 11
yeah it does seem obvious doesnt it

spent hours looking through help files and the internet until i managed o find something

sorted now guys so thanks again for your help

Alex
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On