View Single Post
  #11 (permalink)  
Old January 23rd, 2007, 02:24 PM
Quick209 Quick209 is offline
Authorized User
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2005
Location: Fresno, California, USA.
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts

Okay, I am lost on all the logic I see above so I am going to assume that you are working on a converter to convert your database passwords from plain text to SHA1. To do this, your way is going to have unpredictable results. You are missing your primary key so you can tell what record you are specifically editing and you aren't really looping through each password.

I can't write VB fluently, but I can understand it so I will just put in plain text what I think should happen.

First, do not reuse the connection, command or data adapter/reader for input and output into the database. Instead you will need a separate Connection, command and adapter or datasource for input and output.

First focus on the code that will cycle through your database and retrieve the password and whatever the primary key is. Get that part working first and output it to a textbox so you have a list showing the primary key column and the password. You will have to use a "While" loop with the datareader like gBianchi mentioned above because that reader keeps reading records each time the read method is called and returns true until there are no more record to return and then it returns false. Each call of the read method cycles to the next record found according to your query.

Once you are sure you have your data being retrieved, change the output lines you added to output your data to a textbox and change them to a method that will take the key and the password. You will create a new method that will access the database from a totally different connection, command and datawriter. This will just be used to update the record but you will add a "Where" clause to specify when the primary key equals the primary key you sent to the method. After you are done, make sure you close the writer.

What should happen is each password that is read with the primary key is passed to the update method. In there you will convert the password and then update the matching record. Since the whole thing is in a while loop, it will keep going until the datareader reads null. :)

A easier process, if the database is small, is just fill a data table with the same info and cycle through that and convert the password and then update with the newly updated datatable. :)

Reply With Quote