我试图通过使用下面的代码在插入新记录后立即从表中获取最大值。
objDataAccess.CmdText("Insert into Patientdetails(Patient_Name,Patient_Age,Patient_Sex,Patient_RfdDr,LabId,Sample_Rcvd,Sample_Dlvd,AmtToPay,AmtPaid,AmtPending)Values('" + Name + "','" + Age + "'," + sex + ",'" + doctor + "'," + LabId + "," + smprcvd + ",'" + smpdlvrd + "'," + AmtoPay + "," + AmtPaid + ","+AmtPndg+")");
dtpid = objDataAccess.CmdSelect("Select Max(Patient_Id) from Patientdetails");
我获得了以前的记录最大值 如果我放置断点并检查它是否从我插入的表中获取精确(新输入的记录)值。
如何获取最后插入的值
答案 0 :(得分:0)
你能试试吗?不确定maximum value
你的意思,但假设你想得到最后插入的记录,其中Patient_Id将是最大的数字......
Select Patient_Id
from Patientdetails
ORDER BY Patient_ID desc Limit 1;