How to update a single row in C# mysql -


my problem

  1. it updates data same id. because have multiple data same id. [see picture below].

  2. i want update row near expiration (30 days). don't want items expired.

here code:

        (int = 0; < datagridviewpos.rows.count; i++)         {             cmd = new mysqlcommand(@"update inventory2 set quantity = @quantity itemid = @itemid order expiry", sqlconnection);             //codehere         } 

screenshot

thanks

update:

       (int = 0; < datagridviewpos.rows.count; i++)         {             cmd = new mysqlcommand(@"select * inventory2 itemid = @itemid order expiry", sqlconnection);             //codehere              cmd = new mysqlcommand(@"update inventory2 set quantity = @quantity itemid = @itemid , curdate() < expiry order expiry", sqlconnection);              //codehere         } 

you need check expiration in sql ie

where itemid = @itemid , curdate() < expiry 

the exact nature of depends on how define "near"

where itemid = @itemid , date_add(curdate(),interval 30 day) < expiry  

this within 30days of expiry

once have "near" date combine select max

and expiry = (select max(expiry) inventory2 itemid = @itemid) 

so largest

edit: information added says want edit records not expired exact opposite of original question seemed imply such need do

expiry between curdate() , date_add(curdate(),interval 30 day) 

this expiry in next 30days hasn't expired


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -