Trouble with Insert Command

TheWizardofInt

Well-known member
Joined
Dec 31, 1969
Messages
333
Location
Orlando, FL
This code:

Code:
        Dim sName As String = txtLogin.Text
        Dim sPwd As String = txtPwd.Text
        Dim MyConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database/GMVar.mdb") & ";")
        MyConnection.Open()
        Dim MyCommand As New OleDb.OleDbCommand("SELECT [AUTOID] FROM [VARS] WHERE Login=" & sName & " AND " & _
            "pwd=" & sPwd & "", MyConnection)
        Dim MyReader As OleDb.OleDbDataReader = MyCommand.ExecuteReader()
        If MyReader.Read Then
            lblAnnounce.Text = MyReader.GetString(0)
            MyConnection.Close()
            Exit Sub
        End If
        MyReader.Close()
        MyCommand.Dispose()
        Dim sval As String = "Insert Into [VARS] (Login, Pwd) Values(" & sName & ", " & sPwd & ")"
        MyCommand = New OleDb.OleDbCommand("Insert Into [VARS] ([Login], [Pwd]) Values(" & sName & ", " & sPwd & ")", MyConnection)
        MyCommand.ExecuteNonQuery()
        MyConnection.Close()
        MyCommand.Dispose()

Gives me a must use updareable query error.

What I am doing is updating an Access database called GMVars, Table Vars, with a new Login and Pwd to let a new person into my site
 
In Acess, an append query is used to insert new records, i.e. the INSERT INTO sql statement is utilized.
An update query utilizes UPDATE SET sql language.
Sounds like your access db is rejecting the insert into and wants an update set statement.
Check your autoid field I dont think your db engine is recognizing the new record and creating a new autoid for you. Thus it is trying to update the Login and Pwd fields and wants the update statement .

Jon
 
Your code seems ok so far.
I dont think the error lies within the AutoId, because the error-message would be different, if so.
You created a variable "sval" for the insert-statement. You could take the content of the variable and execute it in the query-editor of Access to see what happens.
 
When you say, Check the autoid field, what do you mean?

It is set to Increment in Access - is there another command I should be sending, or should I be sending a new value for autoid?
 
Problem is not with code. It is with permissions for the Directory containing the Access file for the ASPNET user.

Bad news... I dont know how do change permissions. I am waiting for replies for my post on the same matter. If I get anything will tell you.

Happy Coding,
Amol
 
Here is how you change permissions in XP Pro, which I am guessing is giving you the problem

First, you have to be in NTFS. You cannot enable the permissions tab in Fat32

Second, in Windows Explorer, you go to the Tools/Folder Options/View tab

Go to the end of the list of views and DESELECT Use simple file sharing

Believe it or not, that means the Securities Tab to some blue-haired monkey at MS

Now that you can see the securities tab under Properties in Windows Explorer, you can use the Advanced button to add the ASPNet user to your list of users for the table, and give the user full control, which DID fix the problem
 
Back
Top