开发者

How do I Insert data in MSAcess 2010?

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 &开发者_JAVA百科amp; "' ,'" & _
                     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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜