CommandObject.ExecuteReader ERROR

  • Thread starter Thread starter Duppypog
  • Start date Start date
D

Duppypog

I'm trying to update a record in an Access database. When I click the submit
button on my form to execute the code, I'm getting an error, "Operation must
use an updateable query. "

To troubleshoot, I created the same query within the database, and it
updates the record. So why can't I get it to execute from my asp.net code?

PLEASE HELP!



Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSubmit.Click

'First test that new password is a strong password, if true, hash
the password

If ValidPWD(txtNewPW.Text) Then

Dim hshPW As String

hshPW =
FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text,
"sha1")



'Once you have a strong password, test that the username and
password match a valid user in the database

If ValidateUser(txtUsername.Text, hshPW) Then

'Next test that the two New PW textbox values match

If txtNewPW.Text = txt2NewPW.Text Then

Dim hshNewPW As String

hshNewPW =
FormsAuthentication.HashPasswordForStoringInConfigFile(txtNewPW.Text,
"sha1")



Dim strUser As String = txtUsername.Text

Dim d = Now.ToShortDateString

Dim sSQL As String

Dim dr As OleDbDataReader

Dim retVal As Boolean = False



Dim cnn As New
OleDbConnection(Constants.OleDbConnectionString)



cnn.Open()

sSQL = "UPDATE tblUsers SET strPASSWORD = '" & hshNewPW
& "' WHERE (strUserName = '" & strUser & "')"



Dim objCommand As OleDbCommand = New OleDbCommand(sSQL,
cnn)

dr = objCommand.ExecuteReader()



retVal = True


'FormsAuthentication.RedirectFromLoginPage(Session("sUser"), False)

Call SetSVariables()



Response.Redirect(Server.MapPath("CompPayOut.aspx"))



objCommand.Dispose()

dr.Close()

cnn.Close()

Else

lblErrorMsg.Text = "The new passwords you entered do not
match. Please type them again."

lblErrorMsg.Visible = True

End If

Else

lblErrorMsg.Text = "The username or password you entered do
not match a user in the database. Please try again."

lblErrorMsg.Visible = True

txtNewPW.Text = ""

txt2NewPW.Text = ""

End If

Else

lblErrorMsg.Text = "You must use a strong password, consisting
of a combination of numbers, special characters and UPPER and lower case
letters. Please try again."

lblErrorMsg.Visible = True

End If

End Sub
 
And that gives me an error "Value of type 'Integer' cannot be converted to
System.Data.OleDb.OleDbDataReader.

I've used similar code in a different application, which lead me to believe
there must be some syntax error somewhere - hoping a sharper eye than mine
might spot it.

Or if you know a better way to update a record, please share. The form just
has two textboxes - one that stores the unique identifier, the other the
field to be changed.

Thanks,
lds
 
I really didn't look at the rest of your code. I just
noticed that you were using an ExecuteReader function to
run a non query. Make sure that your field data types
match what you are updating to.
 
don't assign the data reader in the ExecuteNonQuery
command.

ExecuteNonQuery returns the number of rows effected. I'm
assuming you wrote:

dr = objCommand.ExecuteNonQuery();

instead of the above, just call:

objCommand.ExecuteNonQuery();
 
Actually, it was a permissions error - I hadn't provided sufficient rights
to the ASPNET user.

Thanks for your help!!
lds
 
Back
Top