views:

452

answers:

3

In a VB.Net application, how can I either:

Find the dropDownList selectedIndex position of something just added to a database.

Have a form restart with the most recently-added entry showing in the DropDownList, by way of modifying the inline SQL query to display by date/time added.

A: 

i think this is more of an sql question than vb.net. All you need to do on the vb end is to use datasource and databind on the dataset return from your sql query to your dropdownlist. And on SQL you just need to ORDER BY the datetime column.

waqasahmed
Thanks, that definitely sounds like the direction I need to go in. I'll try it tonight and let you know if I was able to figure it out.
A: 

If VB.Net has a DetailsView I would use that. I know ASP.Net has one.

Joe Philllips
A: 

I assume you're talking about a ComboBox with it's style property set to DropDownList?

Two ways you can do this:

1) Order your SQL results with the newest item first, as suggested above.

2) Get the ID of the last item (select top 1 id order by id desc) and set the ComboBox.SelectedValue to this ID, after you have bound the data source.

The second method is better if you prefer to have your list sorted alphabetically. I assume your CombBox.ValueMember is set the the same ID field on binding.

Wez