我编写了一个导入程序,用于删除SQLServer数据库中所有数据表的所有数据,并用Access数据库中的新数据替换数据。问题是,尽管它在最后给出了“导入完成!”的消息框,但SQLServer数据似乎保持不变。我知道这里有很多代码,为此道歉,但是有人可以建议为什么数据不会改变吗?
我想也许是因为我的删除语句都必须是一个事务,然后插入一个单独的事务?我错过了什么吗?
[ERROR] : linker: readlink('/proc/self/fd/21') failed: Permission denied [fd=21]
[ERROR] : linker: warning: unable to get realpath for the library "/data/app/com.techintegrity.ekko-1/lib/arm/libti.admob.so". Will use given name.
[ERROR] : TiApplication: (KrollRuntimeThread) [77,153] Sending event: exception on thread: KrollRuntimeThread msg:java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/com.techintegrity.ekko-1/lib/arm/libti.admob.so: has text relocations; Titanium 5.2.0,2016/02/20 08:05,384775e
[ERROR] : TiApplication: java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/com.techintegrity.ekko-1/lib/arm/libti.admob.so: has text relocations
[ERROR] : TiApplication: at java.lang.Runtime.loadLibrary(Runtime.java:372)
[ERROR] : TiApplication: at java.lang.System.loadLibrary(System.java:1076)
[ERROR] : TiApplication: at org.appcelerator.kroll.runtime.v8.V8Runtime.loadExternalModules(V8Runtime.java:132)
[ERROR] : TiApplication: at org.appcelerator.kroll.runtime.v8.V8Runtime.initRuntime(V8Runtime.java:99)
[ERROR] : TiApplication: at org.appcelerator.kroll.KrollRuntime.doInit(KrollRuntime.java:205)
[ERROR] : TiApplication: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:114)
答案 0 :(得分:1)
在每个CommandText之后,您必须显式调用ExecuteNonQuery
函数,以便在数据库中执行该命令。
示例:
sql.Parameters.Clear
sql.CommandText = "DELETE FROM tblModules"
sql.Transaction = tr
sql.ExecuteNonQuery()
sql.Parameters.Clear
sql.CommandText = "DELETE FROM tblContracts"
sql.Transaction = tr
sql.ExecuteNonQuery()
...
答案 1 :(得分:0)
我猜删除语句没有运行,因为您的数据保持不变。您确定正确连接数据库吗? 这就是我通常做的事情:
Using sqlCon as new sqlConnection(sqlConString)
Using sqlCmd as new sqlCommand("DELETE FROM tbl", slqCon)
If sqlCmd.ExecuteNonQuery > 0 Then
//Delete successful. Import new data.
End If
End Using
End Using
您可以尝试使用此功能轻松删除所有表中的数据,而不是定义每个表。如果您要从数据库下的所有表中删除数据,请仅使用此项。
编辑:由于您已经通过了连接。
Using sqlCmd as new sqlCommand("DECLARE @SQL VARCHAR(MAX)
SET @SQL = 'DELETE FROM ?'
EXEC sp_MSForEachTable @SQL", con)
//con.Open If you haven't opened it through another method.
If sqlCmd.ExecuteNonQuery > 0 Then
//Delete successful. Import new data.
End If
End Using