Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error executing the ExecuteNonQuery command 1

Status
Not open for further replies.

vatawna

Programmer
Joined
Feb 24, 2004
Messages
67
Location
US
I have the following simple code:


Private ConStr As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Server.MapPath("\someDatabase.mdb")

Private Sub Page_Load(Sender As Object, E As EventArgs) Handles MyBase.Load
' Response.Redirect("home.html")

Dim Con As New OLEDBConnection(ConStr)
Dim InsertStr As String = "Insert into someTable(ComputerIP, LogTime) values('" & Request.UserHostAddress & "', '" & DateTime.Now & "')"
Dim InsertCommand As New OLEDBCommand(InsertStr, Con)
Dim RowInserted As Integer

Try
Con.Open()
RowInserted = InsertCommand.ExecuteNonQuery()

Catch Ex As Exception
Response.Write("Error: " & Ex.Message)

Finally
If Not Con Is Nothing Then
Con.Close()
End If
End Try
End Sub


I got the error message "Operation must use an updateable query". Does anyone know how to fix this?

Thanks
 
ExecuteNonQuery doesn't return anything, so:

RowInserted = InsertCommand.ExecuteNonQuery()

should instead be:

RowInserted = Convert.ToInt32( InsertCommand.ExecuteScalar() )


As far as the actual error you're getting, it looks like it's related to permissions issues. Does the application have the access it needs to the DB?
 
actually RowInserted would contain the number of rows affected by the sql command since ExecuteNonQuery return such a number.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Oops. Thanks for the correction, DaZZleD. P-) Star from me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top