Bee*_*gud 3 c# sql-server compact-framework identity-insert
在Sql Server CE中出现了标识列的问题
使用Server explorer时,在VS2008中,执行以下脚本
SET IDENTITY_INSERT testTable ON; 插入testTable(id,name)值(1,'Something')SET IDENTITY_INSERT testTable ON;
发送以下消息错误'不支持Set SQL构造或语句.但然后插入行好吗?!?!?!
无论如何,当我尝试通过C#做同样的事情时,将该脚本作为命令文本,它无法说错误在"插入关键字"中
我理解,对于SQL SERVER CE,该命令当时只接受一个批处理命令,所以在这种情况下我们有三个命令(它可以与完整的SQLServer一起工作)任何想法?
如果您使用的是SqlCe 3.5,那么这应该可行.但是,您需要将其作为两个单独的命令发送.你不能用";"分隔命令 或者在SqlCe中"GO".相反,你需要做这样的事情:
SqlCeConnection connection = new SqlCeConnection(connectionString);
SqlCeCommand identChangeCommand = connection.CreateCommand();
identChange.CommandText = "SET IDENTITY_INSERT SomeTable ON";
SqlCeCommand cmd = connection.CreateCommand();
cmd.CommandText = "INSERT INTO testTable (Id, column1, column2..) VALUES (10,val1,val2...)";
try
{
connection.Open();
identChange.ExecuteNonQuery();
cmd.ExecuteNonQuery();
}
catch (SqlCeException ex)
{
//log ex
}
finally
{
connection.Close();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9408 次 |
| 最近记录: |