Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
'open connection if it is not yet open
cnn.Open()
End If
cmd.Connection = cnn
'check whether add new or update
If Me.txtcheckID.Tag & "" = "" Then
'add new
'add data to table
cmd.CommandText = "INSERT INTO student(checkid, branch, amount, type, status, date, address) " & _
" VALUES(" & Me.txtcheckID.Text & ",'" & Me.txtBranch.Text & "','" & _
Me.cboType.Text & "','" & Me.txtStatus.Text & "','" & _
Me.txtAddress.Text & "','" & Me.txtDate.Text & "','" & Me.txtAmount.Text & "')"
cmd.ExecuteNonQuery()
Else
'update data in table
cmd.CommandText = "UPDATE student " & _
" SET checkid=" & Me.txtcheckID.Text & _
", branch='" & Me.txtBranch.Text & "'" & _
", type='" & Me.cboType.Text & "'" & _
", status='" & Me.txtStatus.Text & "'" & _
", address='" & Me.txtAddress.Text & "'" & _
", amount='" & Me.txtAmount.Text & "'" & _
", date='" & Me.txtDate.Text & "'" & _
" WHERE checkid=" & Me.txtcheckID.Tag
cmd.ExecuteNonQuery()
End If
'refresh data in list
RefreshData()
'clear form
Me.btnClear.PerformClick()
'close connection
cnn.Close()
答案 0 :(得分:0)
cmd.CommandText = "INSERT INTO student(checkid, branch, amount, type, status, date, address) " & _
" VALUES(" & Me.txtcheckID.Text & ",'" & Me.txtBranch.Text & "','" & _
Me.cboType.Text & "','" & Me.txtStatus.Text & "','" & _
Me.txtAddress.Text & "','" & Me.txtDate.Text & "','" & Me.txtAmount.Text & "')"
很抱歉,如果我是愚蠢的,但在地址之间的CommandText字符串中有2个空格)和第一个换行错误导致的VALUES?不确定VB和OleDB如何处理空格,我的帐户太新了,无法发表评论......