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 > Delphi SQL Insert :( ohnoes

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-09, 06:58
Roxlet Roxlet is offline
Registered User
 
Join Date: Jul 2009
Location: South Africa
Posts: 3
Red face 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
Attached Thumbnails
Delphi SQL Insert :( ohnoes-error.jpg  

Last edited by Roxlet; 07-04-09 at 07:13.
Reply With Quote
  #2 (permalink)  
Old 07-04-09, 08:26
r937 r937 is online now
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-04-09, 08:53
Roxlet Roxlet is offline
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.
Reply With Quote
  #4 (permalink)  
Old 07-04-09, 09:02
Roxlet Roxlet is offline
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
Reply With Quote
  #5 (permalink)  
Old 11-24-09, 10:12
ciksha ciksha is offline
Registered User
 
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?
Reply With Quote
  #6 (permalink)  
Old 11-24-09, 10:14
ciksha ciksha is offline
Registered User
 
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?
Reply With Quote
  #7 (permalink)  
Old 12-30-09, 23:04
jbedson jbedson is offline
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.
Reply With Quote
Reply

Thread Tools
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