the followings ar my code:
Private Sub 訂_Click()
Dim IntUnit As Integer
  Dim AmtUnit As Integer

Dim theConnection As New ADODB.Connection
  Dim strSQL As String

IntUnit = txtUnit
  IntAmt = txtAmt

strSQL = "INSERT INTO OrderTable"
  strSQL = strSQL & "(Unit, Amt)"
  strSQL = strSQL & "VALUES("
  strSQL = strSQL & "&IntUnit&"
  strSQL = strSQL & "&IntAmt&"

   With theConnection
  .Open "DSN=OrderDSN"
  .Execute strSQL
  .Close
  End With
  Set theConnection = Nothing
  strSQL = ""
  
End Sub
when i press F5, it said runtime error '13'. type mismatch on (Dim IntUnit As Integer). So what is my problem? is anyone can help me?
創作者介紹
創作者 vbqa 的頭像
vbqa

小吳 VBQA 程式設計討論

vbqa 發表在 痞客邦 留言(7) 人氣()


留言列表 (7)

發表留言
  • johnson
  • 你好:
    在資料庫中,可能unit的型態,不是integer,去檢查一下喔!
  • Doug
  • hi, thx for help.
    but the type in access and the type in VB is the same.....
    so do u know whats the problem?
    Thanks
  • 大漢堡
  • (1).組成sql語法
    strSQL = "INSERT INTO OrderTable"
    strSQL = strSQL & "(Unit, Amt)"
    strSQL = strSQL & "VALUES("
    strSQL = strSQL & IntUnit & ","
    strSQL = strSQL & IntAmt & ")"
    (2).看不到IntAmt的宣告且沒用到AmtUnit變數,這裡是不是打錯了呢?
    (3).在執行這段程式時,txtUnit及txtAmt的內容是什麼?
    可能出錯的問題點蠻多的,建議您在開頭加上Option Explicit,且用Ctrl+F5執行程式,讓一些錯誤提早浮現後,才有辦法專心在資料庫的操作上。
  • Doug
  • thx. i hv a try 1st
  • Doug
  • i try ur suggestions b4.....but
    i cant put "," at the end of IntUnit ,
    it said Compile error. Expected:end of statement
    If without "," and just ") at the end of IntAmt, it said syntax error when i run the program
    strSQL = strSQL & IntUnit & ","
    strSQL = strSQL & IntAmt & ")
    both txtInt and txtAmt is the textbox name where i enter int and amt integer.
    Thx
    Doug
  • 大漢堡
  • strSQL = strSQL & IntAmt & ")  <--您的語法
    strSQL = strSQL & IntAmt & ")" <--我的語法
    是不是這個雙引號的關係?
  • Doug
  • thx.