gpt4 book ai didi

c# - SQL Server CE 查询无法在 c# 中执行,但在 DBMS 中有效

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:00 24 4
gpt4 key购买 nike

我正在尝试在 sql 查询中运行一堆 SQL 语句。查询和代码如下所示:

    private void cancelTestCaseCreationWizard()
{
string deleteTestCaseCmd = @"
DELETE FROM column_correlation WHERE test_id IN (SELECT test_id FROM test WHERE test_case_id = @tcid);
DELETE FROM data_range WHERE test_id IN (SELECT test_id FROM test WHERE test_case_id = @tcid);
DELETE FROM permitted_values WHERE test_id IN (SELECT test_id FROM test WHERE test_case_id = @tcid);
DELETE FROM test WHERE test_case_id = @tcid;
DELETE FROM parameter WHERE parameter_set_id IN (SELECT parameter_set_id from parameter_set WHERE test_case_id = @tcid);
DELETE FROM parameter_set WHERE test_case_id = @tcid;
DELETE FROM test_case WHERE test_case_id = @tcid;";
List<SqlCeParameter> param = new List<SqlCeParameter>();
SqlCeParameter tcid = new SqlCeParameter("@tcid", SqlDbType.Int);
tcid.Value = reservedTestCaseId;
param.Add(tcid);
DatabaseInteraction.DMLQuery(deleteTestCaseCmd, param);
Dispose();
}


public static int DMLQuery(string query, List<SqlCeParameter> parameters)
{
int rowsAffected = -1;
try
{
DBConn.Open();
var tran = DBConn.BeginTransaction();
SqlCeCommand comm = new SqlCeCommand(query, DBConn, tran);
foreach (SqlCeParameter par in parameters)
{
comm.Parameters.Add(par);
}
comm.ExecuteNonQuery();
tran.Commit();
}
catch (SqlCeException e)
{
MessageBox.Show("Error executing DML query \n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return -2;
}
DBConn.Close();
return rowsAffected;
}

执行上述代码后,我得到消息:

Error executing DML query 
There was an error parsing the query. [ Token line number = 3,Token line offset = 41,Token in error = DELETE ]

我查了@tcid 的值,是正确的。查询本身在 DBMS 中工作正常。什么可能导致此错误?

最佳答案

SQL Server Compact does not support batch query execution. You have to run the each statement seperately. You can reuse the SqlCeCommand object to execute more than one query though.

http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/d6f1db96-8724-4376-990e-3f6da18c2d08/

关于c# - SQL Server CE 查询无法在 c# 中执行,但在 DBMS 中有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16658525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com