2010-08-13 50 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

虽然错误是不同的,我发现,每一个值是文本,即用引号包围着,这似乎有点不太可能。