hi guy's
how to show last (maximum) ID from table (access database) in label on the Form ...
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 13, 2014, 6:06 AM
ghasem dehPosted Aug 13, 2014, 10:19 AM
ghasem dehPosted Aug 13, 2014, 5:45 AM
VulpesPosted Aug 13, 2014, 4:16 AM
ghasem dehPosted Aug 12, 2014, 11:37 PM
first use this code :
con.Open();
string str;
str = "SELECT Num FROM Pic;";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
reader.Read();
label1.Text = reader["Num"].ToString() + " Number";
butt display number 1 from table ... i want display last number !
now use this code :
con.Open();
string str;
str = "SELECT LAST(Num) FROM Pic;";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
reader.Read();
label1.Text = reader["Num"].ToString() + " Number";
error in last line:
( Index Out Of Rang Exception Was Unhandled)
Ramesh MaruthiPosted Aug 12, 2014, 11:04 AM
Hemant SrivastavaPosted Aug 12, 2014, 11:01 AM
Ramesh, Last() works only in MS Access but not in SQL Server, MySQL, Oracle.
So the alternative of LAST() is :
SELECT TOP 1 column_name FROM table_name
ORDER BY column_name DESC;
If it helps you, please accept the answer.
Ramesh MaruthiPosted Aug 12, 2014, 10:35 AM
Dipankar BiswasPosted Aug 12, 2014, 7:43 AM