views:

29

answers:

2

I need to insert the data into an MS Access database of (2010) with Asp.net (VS 2005) Please check the code below. When I run the code I get an Error on ExecuteNonQuery.

Operation must use an updateable query

Public Function InsertScheme(ByVal pScheme As Scheme) As Boolean
    Dim a As String = "Provider=Microsoft.ACE.OLEDB.12.0;  " & _
                        "Data Source=C:\AAAAA.accdb;" & _
                        "Persist Security Info=False;"
    Dim conn As OleDbConnection = New OleDbConnection(a)

    'ConfigurationManager.AppSettings("connection").ToString()
    conn.Open()
    Dim lOledb As New OleDbCommand
    lOledb.Connection = conn
    lOledb.CommandType = CommandType.Text
    'lOledb.CommandText = "INSERT INTO Scheme ( SchemeTitle, SchemeCode, " & _
    '                    "Details, Pre-Assesment Cost, Stage1, " & _
    '                    "Stage1 Limit, " & _
    '                    "S1 Premium, S1 Days Allowed, S1 deferred, " & _
    '                    "Stage2, " & _
    '                    "Stage2 limits, S2 Premium, S2 Days Allowed, " & _
    '                    "S2 Deferred, Stage3, Stage3 Limit, S3 Premium, " & _
    '                    "S3 Days Allowed, S3 Deferred, " & _
    '                    "Monthly Finance Rate, " & _
    '                    "Allow Financial Loss, Schedule Document, " & _
    '                    "Policy Wording, Active ) " & _
    '         "values ('" & pScheme.SchemeTitle & "' ,'" & _
    '                 pScheme.SchemeCode & "' ,'" & _
    '                 pScheme.Details & "' ,'" & _
    '                 pScheme.PreAssesmentCost & "' ,'" & _
    '                 pScheme.Stage1 & "' ,'" & _
    '                 pScheme.Stage1Limit & "' ,'" & _
    '                 pScheme.S1Premium & "' ,'" & _
    '                 pScheme.S1DaysAllowed & "' ,'" & _
    '                 pScheme.S1Deferred & "' ,'" & _
    '                 pScheme.Stage2 & "' ,'" & _
    '                 pScheme.Stage2Limit & "' ,'" & _
    '                 pScheme.S2Premium & "' ,'" & _
    '                 pScheme.S2DaysAllowed & "' ,'" & _
    '                 pScheme.S2Deferred & "' ,'" & _
    '                 pScheme.Stage3 & "' ,'" & _
    '                 pScheme.Stage3Limit & "' ,'" & _
    '                 pScheme.S3Premium & "' ,'" & _
    '                 pScheme.S3DaysAllowed & "' ,'" & _
    '                 pScheme.S3Deferred & "' ,'" & _
    '                 pScheme.MonthlyRate & "' ,'" & _
    '                 pScheme.AllowLoss & "' ,'" & _
    '                 pScheme.ScheduleDocument & "' ,'" & _
    '                 pScheme.PolicyWording & "' ,'" & _
    '                 pScheme.Active & _
    '                 "')"
    lOledb.CommandText = "INSERT INTO Scheme " & _
             "Values ('" & pScheme.SchemeTitle & "' ,'" & _
                     pScheme.SchemeCode & "' ,'" & _
                     pScheme.Details & "' ,'" & _
                     pScheme.PreAssesmentCost & "' ,'" & _
                     pScheme.Stage1 & "' ,'" & _
                     pScheme.Stage1Limit & "' ,'" & _
                     pScheme.S1Premium & "' ,'" & _
                     pScheme.S1DaysAllowed & "' ,'" & _
                     pScheme.S1Deferred & "' ,'" & _
                     pScheme.Stage2 & "' ,'" & _
                     pScheme.Stage2Limit & "' ,'" & _
                     pScheme.S2Premium & "' ,'" & _
                     pScheme.S2DaysAllowed & "' ,'" & _
                     pScheme.S2Deferred & "' ,'" & _
                     pScheme.Stage3 & "' ,'" & _
                     pScheme.Stage3Limit & "' ,'" & _
                     pScheme.S3Premium & "' ,'" & _
                     pScheme.S3DaysAllowed & "' ,'" & _
                     pScheme.S3Deferred & "' ,'" & _
                     pScheme.MonthlyRate & "' ,'" & _
                     pScheme.AllowLoss & "' ,'" & _
                     pScheme.ScheduleDocument & "' ,'" & _
                     pScheme.PolicyWording & "' ,'" & _
                     pScheme.Active & _
                     "')"
    Return lOledb.ExecuteNonQuery() > 0
    conn.Close()
End Function
+1  A: 

Maybe this link can help

Carlos Muñoz
A: 

While the error would be different, I notice that every value is text, that is, delimited with quotes, this seems a little unlikely.

Remou