1 (edited by lara.0080 2024-04-09 15:54:32)

Topic: Problem in Insert SQL for Boolean [Solved]

Where is  the problem ??? (why i can't  give a Boolean value from variable to Boolean column!? )

empid : Integer;

    valueAsBoolean1,valueAsBoolean2,valueAsBoolean3,valueAsBoolean4,valueAsBoolean5,valueAsBoolean6,valueAsBoolean7,: boolean;

begin


empid := 3 ;

           if     StrToInt(form1.Edit1.Text) <> 0 then
           begin
             valueAsBoolean1 := true
           end else   valueAsBoolean1 := false  ;

           if    StrToInt(form1.Edit2.Text) <> 0 then
           begin
             valueAsBoolean2 := true
           end else   valueAsBoolean2 := false   ;

               if     StrToInt(form1.Edit3.Text) <> 0 then
           begin
             valueAsBoolean3 := true
           end else   valueAsBoolean3 := false ;

                if     StrToInt(form1.Edit4.Text) <> 0 then
           begin
             valueAsBoolean4 := true
           end else   valueAsBoolean4 := false    ;

       if     StrToInt(form1.Edit5.Text) <> 0 then
           begin
             valueAsBoolean5 := true
           end else   valueAsBoolean5 := false  ;

       if     StrToInt(form1.Edit6.Text) <> 0 then
           begin
             valueAsBoolean6 := true
           end else   valueAsBoolean6 := false   ;

       if     StrToInt(form1.Edit7.Text) <> 0 then
           begin
             valueAsBoolean7 := true
           end else   valueAsBoolean7 := false   ;



         SQLExecute('INSERT INTO Employ_Days (Id_empl, day1, day2, day3, day4, day5, day6, day7) VALUES ("'+empid +'", "'+ valueAsBoolean1 + '" ,"' + valueAsBoolean2 + '","' + valueAsBoolean3 + '","' + valueAsBoolean4 + '","' + valueAsBoolean5 +' ","' + valueAsBoolean6 + '","' +valueAsBoolean7+ '")');
              form1.TableGrid1.dbUpdate;



Okay, I have boxes from 1 to 7 with values and names: edit1 - edit2 - edit3 - edit4 - edit5 - edit6 - edit7. I also have a table with the following columns holding true or false values (boolean variables): day1 - day2 - day3 - day4 - day5 - day6 - day7, and a foreign key from the Employees table called Id_Employ, and the name of the table is 'work_Days. I have a combobox to select the teacher. I want to check box 1, and if its value is greater than 0, I want to put a check mark in the column day1, and so on with the rest of the boxes and columns, all in one row, storing the Employ's key in Id_Employ.

Post's attachments

Attachment icon test9.zip 338.03 kb, 75 downloads since 2024-04-09 

Re: Problem in Insert SQL for Boolean [Solved]

Boolean values are stored as 1 or 0 in the database, where do your valueasbooleanxxx come from?

3 (edited by lara.0080 2024-04-09 12:09:23)

Re: Problem in Insert SQL for Boolean [Solved]

tcoton wrote:

Boolean values are stored as 1 or 0 in the database, where do your valueasbooleanxxx come from?


if you take a look on this

 if    StrToInt(form1.Edit2.Text) <> 0 then
           begin
             valueAsBoolean2 := true
           end else   valueAsBoolean2 := false   ;

if (editx.text) is not 0 this will give the valueAsBooleanx The true value..if it is  0 it will take false value  ..

Re: Problem in Insert SQL for Boolean [Solved]

Thanks after 10 Hours i have found a solution ...