Write out the database in this form:
I haven't tested this code, but I hope you get the idea.
You can do it in other ways too by for example making each state and district representing an index in a matrix, but I decided to use an object since I already had code for that from another app.