Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2009
    Location
    South Africa
    Posts
    3

    Red face Unanswered: Delphi SQL Insert :( ohnoes

    procedure TfrmTutoring.btnAddClientClick(Sender: TObject);
    begin
    {ADD CLIENT}
    inc(iNoClients);
    arrClients[iNoClients] := TClient.create('',edtClientName.Text, edtClientSurName.Text, edtClientContact.Text, edtClientLocation.text, strtoint(sedClientGrade.text),0);
    arrClients[iNoclients].setNewClient; {sets the primary key (Client ID) }
    qryTutoring.Active := false;
    qryTutoring.SQL.Clear;
    qryTutoring.SQL.text := 'INSERT INTO Clients Values ("' +arrClients[iNoClients].GetClientID+ '","' + arrClients[iNoClients].GetClientName + '","' +arrClients[iNoClients].GetClientSurname + '","' +arrClients[iNoClients].GetContactNumber +'","'+ arrClients[iNoClients].GetLocation + '",' + inttostr(arrClients[iNoClients].GetGrade)+ ','+ floattostr(arrClients[iNoClients].GetDue) + ');';
    qryTutoring.execSQL;
    qryTutoring.Active := true;
    tblTutoring.Refresh;
    end;
    This code is to write a client to a database for a tutoring program for my IT project. After sauntering through a few errors it now actually saves the insert in the database but gives me the error shown in the attatched 'Error.jpg'

    For the moment I'm using a simple stupid algorithm to generate the primary key just so I can get the framework of the program on track:

    procedure TClient.setNewClient;
    begin
    {Set Client ID}
    fClientID := 'C' + fClientName[1] + copy(fClientSurname,1, 3) + copy(fContactNumber, 4,5);
    fDue := 0;
    end;
    I have yet to put data validation as I want to get the basic SQL working first.

    I have no idea how to remove this error.

    Please help
    Thanks muchly
    Attached Thumbnails Attached Thumbnails Error.jpg  
    Last edited by Roxlet; 07-04-09 at 07:13.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Roxlet
    I have no idea how to remove this error.
    the error message says there's a duplicate value, so ur doing it wrong

    is it possible that your formula --

    'C' + fClientName[1] + copy(fClientSurname,1, 3) + copy(fContactNumber, 4,5);

    can give duplicate client numbers?

    sorry, i don't have too much else to offer, as i don't do delphi, but i was instantly hooked by your icanhascheezburger "oh noes" subject
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2009
    Location
    South Africa
    Posts
    3
    Haha thanks :P

    Lolz, I'm doing something wrong: the unholy beep, error message and pause in my program tells me, the problem is how to fix it

    Yes it could form duplicates in the strange event of similar names and cell numbers- it's a silly algorithm developed for the sake of framework. Even though I'm putting input that won't create duplicates it's giving me issues, and it IS in fact writing to the database :P which is why the error perplexes me. :P

    But thank you for the attempt I'll try a different algorithm using the client number or something.
    Last edited by Roxlet; 07-04-09 at 09:26.

  4. #4
    Join Date
    Jul 2009
    Location
    South Africa
    Posts
    3
    *sigh* nope still doesn't work, even though I'm using the client number (essentially working like an autonumber within the key). Grrr, no work

  5. #5
    Join Date
    Nov 2009
    Posts
    8
    can i ask someting?
    i have done csv file from tutorial Delphi Tutorial, Lesson 15: CSV files, part 2 which load csv file using delphi and success doin that. now i need to insert this csv file into table. how can i do it?

  6. #6
    Join Date
    Nov 2009
    Posts
    8
    can i ask someting?
    i have done csv file from tutorial Delphi Tutorial, Lesson 15: CSV files, part 2 which load csv file using delphi and success doin that. now i need to insert this csv file into table. how can i do it?

  7. #7
    Join Date
    Dec 2009
    Posts
    50
    It sounds like your code is working, the data is being inserted into the table. The exception is being thrown because you have a Key value or Multiple Key values that are meant to prevent duplicate values. Try examaning your Key set up and determine if you can change it. It may help to add a column just for the Key and allow other fields to be duplicated.

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •