How to update a single row in C# mysql -
my problem
it updates data same id. because have multiple data same id. [see picture below].
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 }
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
Post a Comment