关于sqllite更新数据库问题(急)

ryan_allyes 2012-04-18 10:03:53
目前功能需求更新3张表A,B,C ,其3张表ID都是互相关联,并且localstatus字段也是相对应的,我该如何通过一条sql语句update同时更新某个ID下的这三张表对应的数据行中localstatus字段呢??我baidu过都说update只能更新一张表的数据,不能同时更新多张表?难道我要分别更新么?这样在sqllite里就达不到起一个事务来执行3张表的更新了
...全文
488 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ryan_allyes 2012-04-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

C# code

string source="database connections";
using (TranscationScope scope=new TranscationScope(TranscationScope.Required))
{
using(SQLiteConnection cn =new SQLiteConnection(scource))
{
/……
[/Quote]

我是这样写的
C# code
public int ExecuteNonQuery(string[] sql, SQLiteParameter[] parameters=null)
{
int affectedRows = 0;
SQLiteConnection connection = new SQLiteConnection(connectionString);
try
{

OpenCon(connection);
using (DbTransaction transaction = connection.BeginTransaction())
{
foreach (string strsql in sql)
{
using (SQLiteCommand command = new SQLiteCommand(connection))
{
// string str=strsql.Replace("\\", "\\\\");

command.CommandText = strsql;

if (parameters != null)
{

command.Parameters.AddRange(parameters);

}
affectedRows += command.ExecuteNonQuery();

}
}
transaction.Commit();
}

}
catch (Exception ex)
{
AsynLogManager.Trace(ex);
return -1;
}
finally
{
CloseCon(connection);
}
return affectedRows;
}
ryan_allyes 2012-04-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

C# code

string source="database connections";
using (TranscationScope scope=new TranscationScope(TranscationScope.Required))
{
using(SQLiteConnection cn =new SQLiteConnection(scource))
{
/……
[/Quote]
这里的update three 是分别写3条update语句?
迪迦凹凸曼 2012-04-18
  • 打赏
  • 举报
回复

string source="database connections";
using (TranscationScope scope=new TranscationScope(TranscationScope.Required))
{
using(SQLiteConnection cn =new SQLiteConnection(scource))
{
//do something in sql
//update three table
scope.Complete();
}
}
ryan_allyes 2012-04-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lordbaby 的回复:]

lz可以尝试使用一下触发器
[/Quote]
我不能用触发器的,我在.net的sqllite类中拼接sql然后执行的。。如果update拼接不出来一条执行3张表的更新的话 我就得分开update了
迪迦凹凸曼 2012-04-18
  • 打赏
  • 举报
回复
lz可以尝试使用一下触发器

22,294

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧