我正在尝试将文件插入到Access数据库中,这是完全不可能的。
“ ExecuteNonQuery”返回已插入1个文件,但表中没有记录。 问题出在哪里? 预先感谢。
数据库连接正常,我可以从中读取数据
Dim sql As String = "INSERT INTO Cierre (TIPO,CANTIDAD,FECHA,TIENDA,CAJA) VALUES ('A','3,45','16/05/2019 21:05:34','0','0')"
Conn.Open()
Dim cmd As OleDbCommand = New OleDbCommand(sql, Conn)
Dim i = cmd.ExecuteNonQuery()
Conn.Close()
答案 0 :(得分:0)
检查您的连接字符串。使用参数构建命令并使用Using处理
Using OleDbConn As New OleDbConnection("ConnectionString")
Using Cmd As New OleDbCommand("INSERT INTO Cierre (TIPO,CANTIDAD,FECHA,TIENDA,CAJA) VALUES (@TIPO,@CANTIDAD,@FECHA,@TIENDA,@CAJA)", OleDbConn)
Cmd.Parameters.Add("@TIPO", OleDbType.VarChar).Value = "A"
Cmd.Parameters.Add("@CANTIDAD", OleDbType.VarChar).Value = "3,45"
Cmd.Parameters.Add("@FECHA", OleDbType.Date).Value = New DateTime("16/05/2019 21:05:34")
'If these are actually type INT then change OleDbType and insert as INT not string
Cmd.Parameters.Add("@TIENDA", OleDbType.VarChar).Value = "0"
Cmd.Parameters.Add("@CAJA", OleDbType.VarChar).Value = "0"
Cmd.ExecuteNonQuery()
End Using
End Using