hello ,
I have two tables 'contacts' (which has name, email and group name, groupname is foreign key) and 'groups'(which has groupname and is a primary key). 'Groups' is a master table. Also, I have two forms where in I have to let the user enter name and email. and two radio buttons - 'add contact to group' and 'create a new group.' and a button 'add contact'. when user chooses option 2 that is 'add contact to group', an editbox will appear and the user has to add a new group
now there are few validations with this:
a) if the editbox is empty then showmessage 'please enter groupname'
b) check if the groupname entered is not same as in database . because you are creating a new group. so showmessage 'groupname already exists'and exit
in another form i have database connection, 2 msquery and 2 datasources ..all are interlinked.
below is the code : if I check RadioButton2
(the problem is
a) if I just enter name and email, click on Radiobutton2 and press 'add contact 'button, it doesnt show me 'groupname is not entered.'
b) if i enter name, email, select RadioButton2 and enter a groupname which is similar in my groups table, and press 'add contact' button, it throws voilation related to primary key instead of showing message'group name already exists'
And i dont know where problem is. But if I give a unique groupname along with name and email and press 'add contact' button..then it adds all details to 'contacts' table as well as 'groupname' to groups table.
if RadioButton2.Checked then
begin
//check if name is entered
if Edit3.Text<>'' then begin
//check if there is no duplicate entry of groupname
if Edit3.Text<>Form2.MSQuery2.FieldByName('GroupName').AsString then begin
//add the new groupname to groups table
Form2.MSQuery2.Close;
Form2.MSQuery2.SQL.Text:= 'Insert into groups values
gname)';
Form2.MSQuery2.ParamByName('gname').Value:=Edit3.Text;
Form2.MSQuery2.Execute;
// also add the details to contacts table
Form2.MSQuery1.Close;
Form2.MSQuery1.SQL.Text:='Insert into contacts values
name, :mail, :gname)';
Form2.MSQuery1.ParamByName('name').Value:=Edit1.Text;
Form2.MSQuery1.ParamByName('mail').Value:=Edit2.Text;
Form2.MSQuery1.ParamByName('gname').Value:=Edit3.Text;
Form2.MSQuery1.Execute;
showMessage('the new group: '+edit3.Text+ ' and contact details are added.');
exit;
end
else begin
showMessage('Please enter a group name');
exit;
end;
end;
end;
I have two tables 'contacts' (which has name, email and group name, groupname is foreign key) and 'groups'(which has groupname and is a primary key). 'Groups' is a master table. Also, I have two forms where in I have to let the user enter name and email. and two radio buttons - 'add contact to group' and 'create a new group.' and a button 'add contact'. when user chooses option 2 that is 'add contact to group', an editbox will appear and the user has to add a new group
now there are few validations with this:
a) if the editbox is empty then showmessage 'please enter groupname'
b) check if the groupname entered is not same as in database . because you are creating a new group. so showmessage 'groupname already exists'and exit
in another form i have database connection, 2 msquery and 2 datasources ..all are interlinked.
below is the code : if I check RadioButton2
(the problem is
a) if I just enter name and email, click on Radiobutton2 and press 'add contact 'button, it doesnt show me 'groupname is not entered.'
b) if i enter name, email, select RadioButton2 and enter a groupname which is similar in my groups table, and press 'add contact' button, it throws voilation related to primary key instead of showing message'group name already exists'
And i dont know where problem is. But if I give a unique groupname along with name and email and press 'add contact' button..then it adds all details to 'contacts' table as well as 'groupname' to groups table.
if RadioButton2.Checked then
begin
//check if name is entered
if Edit3.Text<>'' then begin
//check if there is no duplicate entry of groupname
if Edit3.Text<>Form2.MSQuery2.FieldByName('GroupName').AsString then begin
//add the new groupname to groups table
Form2.MSQuery2.Close;
Form2.MSQuery2.SQL.Text:= 'Insert into groups values
Form2.MSQuery2.ParamByName('gname').Value:=Edit3.Text;
Form2.MSQuery2.Execute;
// also add the details to contacts table
Form2.MSQuery1.Close;
Form2.MSQuery1.SQL.Text:='Insert into contacts values
Form2.MSQuery1.ParamByName('name').Value:=Edit1.Text;
Form2.MSQuery1.ParamByName('mail').Value:=Edit2.Text;
Form2.MSQuery1.ParamByName('gname').Value:=Edit3.Text;
Form2.MSQuery1.Execute;
showMessage('the new group: '+edit3.Text+ ' and contact details are added.');
exit;
end
else begin
showMessage('Please enter a group name');
exit;
end;
end;
end;