看板 Database 關於我們 聯絡資訊
資料庫名稱:SQLite3, Office 365 ACCESS 資料庫版本: 內容/問題描述: 我是非資工背景的初學者 在使用Excel VBA嘗試使用sql update Dim Conn As Object Dim SQL As String, Dbtype As String Dbtype = "Access" '選擇使用Access或是SQLite 'Dbtype = "SQLite" Set Conn = connectSQL(Dbtype) SQL = "update book set price = 500 where id = 2" Conn.Execute SQL Conn.Close Set Conn = Nothing 同樣的語法 update book set price = 500 where id = 2 在SQLite可以使用 但在ACCESS卻出現"準則運算式的資料類型不符合" 上網查了之後知道這是因為丟入的資料與資料庫內設定資料型態不合才出現的錯誤 但我不知道錯在哪裡 不知道板上的大大能不能幫小弟解惑 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.136.37.221 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1603215672.A.F95.html
LPH66: 你去查你的 Access 資料庫是怎麼設定的 10/21 04:39
LPH66: 特別是你有用到的欄位 `price` 和 `id` 10/21 04:39
Dim Conn As Object Dim SQL As String, Dbtype As String Dbtype = "Access" 'Dbtype = "SQLite" Set Conn = connectSQL(Dbtype) SQL = "Create table book (ID text, Name text, Page int, Price int)" Conn.Execute SQL Conn.Close Set Conn = Nothing 上面是一開始設定資料庫的程式 Dim Conn As Object Dim SQL As String, Dbtype As String Dbtype = "Access" Set Conn = connectSQL(Dbtype) SQL = "insert into book (ID, Name, Page, Price) values (1, 'Word 2013', 356, 450)" Conn.Execute SQL SQL = "insert into book (ID, Name, Page, Price) values (2, 'Python', 123, 420)" Conn.Execute SQL SQL = "insert into book (ID, Name, Page, Price) values (3, 'C++', 545, 360)" Conn.Execute SQL Conn.Close Set Conn = Nothing 這段是輸入三筆資料 到了後面我發現我除了使用update有"準則運算式的資料類型不符合"的問題外 使用delete from book where id = 3也會出現相同的錯誤訊息 不知道ACCESS的那個ID欄位設定出了什麼問題 晚點回公司再查查 感謝大大
funk6478: 你ID設text 但你where id = 3是把它當數值 10/21 15:35
哇 真的 太感謝你了 ※ 編輯: kurapica1106 (223.136.37.221 臺灣), 10/21/2020 17:18:37