save value of datagrid into MYSQL

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
blairetabay
Posts: 34
Joined: Mon Feb 24, 2014 10:12 am

save value of datagrid into MYSQL

Post by blairetabay » Wed Mar 12, 2014 8:34 am

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


bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: save value of datagrid into MYSQL

Post by bangkok » Wed Mar 12, 2014 10:45 am

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

blairetabay
Posts: 34
Joined: Mon Feb 24, 2014 10:12 am

Re: save value of datagrid into MYSQL

Post by blairetabay » Wed Mar 12, 2014 3:47 pm

hi bangkok,

Thank you :idea:

it work and run smoothly for me.

blairetabay :lol:

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”