Try
If functionmode = "ADD" Then
SQLStr = "INSERT INTO boatmast VALUES ('" & gBoatType & "','" & TxtBoatCode.Text & "','" & TxtBoatName.Text & "','" & Format(txtBP.Text, "##0.#0") & "','" & Format(txtBPM.Text, "##0.#0") & "','" & Format(txtLDA.Text, "##0.#0") & "','" & , 'bpk', '" & Today & "', '" & updtime & "', 'bpk', '" & Today & "', '" & updtime & "')"
End If
conn.Open()
SQLCmd.Connection = conn
SQLCmd.CommandText = SQLStr
SQLCmd.ExecuteNonQuery()
conn.Close()
Catch ex As OdbcException
MsgBox(ex.ToString)
Finally
conn.Close()
End Try
答案 0 :(得分:4)
问题是你两次调用conn.Close()。保留你的finally块上的Close连接。
Try
If functionmode = "ADD" Then
//Supposed this is you columnNAmes //Set parameters
SQLStr = "INSERT INTO boatmast (gBoatType,BoatCode,BoatName,BP, BPM,LDA,bpk,Today,updtime,bpk2,Today2,updtime2) VALUES (@gBoatType,@BoatCode,@BoatName,@BP, @BPM,@LDA,@bpk,@Today,@updtime,@bpk2,@Today2,@updtime2)"
SQLCmd.Parameters.AddWithValue("@gBoatType",gBoatType)
//DO OTHER STUFF TIL @updtime2
conn.Open()
SQLCmd.Connection = conn
SQLCmd.CommandText = SQLStr
SQLCmd.ExecuteNonQuery()
End If
Catch ex As OdbcException
MsgBox(ex.ToString)
Finally
If conn.State = ConnectionState.Open Then conn.Close()
End Try
此致