2010-08-13 51 views
0

我需要使用Asp.net(VS 2005) 將數據插入(2010)的MS Access數據庫。請檢查下面的代碼。當我運行代碼時,ExecuteNonQuery出現錯誤。如何在MSAcess 2010中插入數據?

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 

回答

0

雖然錯誤是不同的,我發現,每一個值是文本,即用引號包圍着,這似乎有點不太可能。