Page 1 of 1

save value of datagrid into MYSQL

Posted: Wed Mar 12, 2014 8:34 am
by blairetabay
I 'm able to save in this way but it will only create one row. I have more than one row in my datagridview. i want that every row of my datagrid will be save according to its row.

Code: Select all


   put the dgData of group "dgGridMed" into theDataA
      put the dgIndexes of group "dgGridMed" into theIndexes
      
      #& cr after 
      repeat for each item theIndex in theIndexes
         put theDataA[theIndex]["Medicine"] & cr  after Medicine
         put theDataA[theIndex]["Preparation"] & cr   after Preparation
         put theDataA[theIndex]["dosage"] & cr  after dosage
         put theDataA[theIndex]["Frequency"] & cr   after Frequency
      end repeat
 
         put "insert into hos_tblmedicineOrder(medName,preparation,dosage,frequency) values (' " &\
         Medicine &" ' , ' " & Preparation& " ' , ' " &dosage & " ', ' " & Frequency& " ' )" into sqlQuery

            revExecuteSQL connID,sqlQuery


Re: save value of datagrid into MYSQL

Posted: Wed Mar 12, 2014 10:45 am
by bangkok
You insert only one row... because you insert only one row !
:)

You need to use a loop like :

Code: Select all

repeat with i = 1 to the number of lines of Medicine
put "insert into hos_tblmedicineOrder(medName,preparation,dosage,frequency) values (' " &\
line i of Medicine &" ' , ' " & line i of Preparation& " ' , ' " & line i of dosage & " ', ' " & line i of Frequency& " ' )" into sqlQuery
revExecuteSQL connID,sqlQuery
end repeat
Or another way, faster (but watchout if you have too many row to insert)

Code: Select all

   put "insert into hos_tblmedicineOrder(medName,preparation,dosage,frequency) values " into sqlQuery
repeat with i = 1 to the number of lines of Medicine
put  (' " & line i of Medicine &" ' , ' " & line i of Preparation& " ' , ' " & line i of dosage & " ', ' " & line i of Frequency& " ' )," after sqlQuery
end repeat

delete last char of sqlQuery
 revExecuteSQL connID,sqlQuery

Re: save value of datagrid into MYSQL

Posted: Wed Mar 12, 2014 3:47 pm
by blairetabay
hi bangkok,

Thank you :idea:

it work and run smoothly for me.

blairetabay :lol: