0

私の問題は、da.Update(dt) で発生します。「OleDbException が処理されませんでした。INSERT INTO ステートメントの構文エラーです」というエラーが表示されます。フィールド名がなく、10列しかない基本的なテーブルを使用したときは機能しましたが、25個のアイテムがあるため機能しません。

Dim dt As New DataTable
    Dim ds As New DataSet

    con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\TPComplete.accdb;Persist Security Info=False;"

    con.Open()
    MsgBox("here")
    ds.Tables.Add(dt)

    Dim da As New OleDbDataAdapter

    da = New OleDbDataAdapter("SELECT * FROM DReview", con)

    da.Fill(dt)



    Dim newRow As DataRow = dt.NewRow

    newRow.Item("Caller") = Caller
    newRow.Item("Associate Name") = Associate
    newRow.Item("Store Number") = "1"
    newRow.Item("Number of Rings") = Ring
    newRow.Item("Time on Hold") = HoldTime
    newRow.Item("Greeting: 3 or fewer rings") = GreetingRings
    newRow.Item("Greeting: Asked for your name") = GreetingAskName
    newRow.Item("Greeting: Offered his/her name") = GreetingOfferedName
    newRow.Item("Greeting: Mentioned TIRE PROS in the greeting") = GreetingTirePros
    newRow.Item("Greeting: Associated acted like they are glad") = GreetingGlad
    newRow.Item("Hold for longer than 1 minute") = holdUpdate
    newRow.Item("Ask for the type of car AND look up the size") = LookupSize
    newRow.Item("Ask appropriate questions about the type of driving") = DailyDriving
    newRow.Item("1st Price Mentioned") = SingleTirePrice
    newRow.Item("1st OTD Price Mentioned") = SingleTireOutDoorPrice
    newRow.Item("Tire Brand") = TireBrand
    newRow.Item("Tire Model") = TireModel
    newRow.Item("Offered several tire choices and prices") = SeveralChoices
    newRow.Item("Did they offer financing options") = Financing
    newRow.Item("Mentioned benefits of the location") = Benefits
    newRow.Item("Appointment") = Appointment
    newRow.Item("How long does it take to put them on") = InstallTime
    newRow.Item("Associate Score") = AssociateScore
    newRow.Item("Time Completed") = hms
    newRow.Item("Completed Date") = ymd



    dt.Rows.Add(newRow)
    Dim cb As New OleDbCommandBuilder(da)
    cb.GetInsertCommand()
    da.Update(dt)
    MsgBox("Saved")
    con.Close()
4

1 に答える 1

0

「INSERT INTO ステートメントの構文エラー」というエラーは、おそらく、使用している列名を OleDb コマンド ビルダーが正しく処理できないことが問題であることを意味します。これらの行:

    newRow.Item("Store Number") = "1"
    newRow.Item("Number of Rings") = Ring
    newRow.Item("Time on Hold") = HoldTime
    newRow.Item("Greeting: 3 or fewer rings") = GreetingRings
    newRow.Item("Greeting: Asked for your name") = GreetingAskName
    newRow.Item("Greeting: Offered his/her name") = GreetingOfferedName
    newRow.Item("Greeting: Mentioned TIRE PROS in the greeting") = GreetingTirePros
    newRow.Item("Greeting: Associated acted like they are glad") = GreetingGlad

「非変数型」の列名があることを示します。これは基本的に、変数名としても使用できない任意の型の名前です。それは { AZ, 0-9 and "_" } だけです。スペースなどを含む非変数型の名前は無効ではありませんが、次のように特別に引用符で囲む必要があります。

    newRow.Item("[Store Number]") = "1"

残念ながら、一部の接続プロバイダー (この場合、OleDb もその 1 つだと思います) は、それを処理できず、引用符を外してしまうため、結果の SQL コマンドが無効になります。

最も簡単な解決策は、名前の代わりに列番号に戻ることです (おそらく、最初にそれがあった理由です)。または、すべての列名を変更して、変数型以外の文字 (スペース、コロンなど) をすべて削除することもできます。

于 2012-08-01T16:31:59.970 に答える