how to get the last Value of a field from MySQL to VB textbox

chinrose

Member
Joined
Jul 13, 2011
Messages
15
Location
Philippines
Programming Experience
Beginner
can any one give me a sample on haw to get the last field of my MySQLdatabase to be written in the VB.net Textbox

for an example, i have my datase Id fields, and i just like to get the last value of this field, which i made it as primary and auto increment,once i press the button in the VB i will get the value of that last field
 
I don't use MySQL so I'm not 100% sure of the correct syntax but in SQL Server it would be like this:
VB.NET:
SELECT MAX(ID) FROM MyTable
You just have to find the MySQL function that is equivalent to MAX, i.e. gets the maximum value from a column. It may actually be the same, but the MySQL documentation can tel you that, or there would likely be lots of examples on the web.

As for how to use that SQL code, see the first example here for the appropriate pattern:

Retrieving and Saving Data in Databases
 
can any one give me a sample on haw to get the last field of my MySQLdatabase to be written in the VB.net Textbox

for an example, i have my datase Id fields, and i just like to get the last value of this field, which i made it as primary and auto increment,once i press the button in the VB i will get the value of that last field


i guess they are diffrent, i cant seems to find to make it work, and i like to show it to a Textbox of a form, thanks for the reply
 
Abt Last record it depends upon your table structure.. " Select * from table order by field1 "
abt text box ..after retrieving data use data reader to read value and insert in text box..
TextBox1.Text=DataReader1.Item(0)
 
Last edited:
Abt Last record it depends upon your table structure.. " Select * from table order by field1 "
abt text box ..after retrieving data use data reader to read value and insert in text box..
TextBox1.Text=DataReader1.Item(0)
That is very bad advice I'm afraid. You are suggesting that you query every column of every row of the table, just to get a single value.

I've already told you exactly what to do so what's the problem? I just searched and apparently MySQL uses MAX just like SQL Server, so you already have all the information you need. You say that you can't make it work yet you haven't provided us with any information about what you tried and what happened when you did.
 
Back
Top