Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 28th, 2012, 05:23 AM
Lucka Lucka is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 1 Lucka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 16 sec
Reputation Power: 0
[Delphi6] insert values on a database

hello,
i'm trying to insert some information about marck of a student in a school. But when I insert, using a DBGrid, the database create a new row!!! ok but i need to insert some information to create a relation with other table.
This is my code to create the relation...

Code:
procedure TForm1.Q1BeforePost(DataSet: TDataSet);
begin
  ADOCommand1.CommandText:=('INSERT INTO registro'+
                               '(IdStuFk, IdMatFk, IdDocFk) '+
                               'VALUES ('+NumIdAlunno+','+numId_Materie+','+numIdDoc+')');
  ADOCommand1.Execute;
end;


Ok,.... but when i insert this value into the database, the database create a new row!!!!!
It's not correct!!!! I need to insert my information in the same row where there is the mark!!! HELP ME!!!!
I tried to save the Mark but it is impossilbe, because there are a lot of information and are all the same(for example Rossi have six but Verdi can have the same mark)



Reply With Quote
  #2  
Old June 28th, 2012, 02:53 PM
majlumbo majlumbo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 251 majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 22 h 50 m 14 sec
Reputation Power: 5
If a blank record is being inserted into your grid, then a new record is already entered into your database waiting for you to post it.

So in your BeforePost Method, you are again inserting a new record, which explains why you are getting a new row.

If you need to set some values of the record before it is posted, then simply assign the columns a value, i.e.
Code:
procedure TForm1.Q1BeforePost(DataSet: TDataSet);
begin
   ADOQuery1ColumnName.AsString := 'This is my new value';
end;


and let the post proceed. You do not want to issue yet another SQL Insert command.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > [Delphi6] insert values on a database

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap