| |
|
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.
|
 |

07-04-09, 06:58
|
|
Registered User
|
|
Join Date: Jul 2009
Location: South Africa
Posts: 3
|
|
Delphi SQL Insert :( ohnoes
|
|
Quote:
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:
Quote:
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
|
Last edited by Roxlet; 07-04-09 at 07:13.
|

07-04-09, 08:26
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,085
|
|
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
|
|

07-04-09, 08:53
|
|
Registered User
|
|
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.
|

07-04-09, 09:02
|
|
Registered User
|
|
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 
|
|

11-24-09, 10:12
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 8
|
|
|
|

11-24-09, 10:14
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 8
|
|
|
|

12-30-09, 23:04
|
|
Registered User
|
|
Join Date: Dec 2009
Posts: 46
|
|
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.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|