ExecuteCommand在SQLsugar
时间: 2024-05-15 08:15:28 浏览: 11
ExecuteCommand是SQLsugar中的一个方法,用于执行SQL语句并返回受影响的行数。
其语法如下:
```csharp
int ExecuteCommand(string sql, params SugarParameter[] parameters)
```
其中,参数sql表示要执行的SQL语句,参数parameters表示SQL语句中的参数。
示例:
```csharp
var db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "server=127.0.0.1;uid=root;pwd=123456;database=test",
DbType = DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
});
string sql = "update user set name = @name where id = @id";
int count = db.ExecuteCommand(sql, new SugarParameter("@name", "张三"), new SugarParameter("@id", 1));
```
上述代码中,首先创建了一个SQLsugar客户端db,然后定义了一个更新语句,最后通过ExecuteCommand方法执行该语句,并传入两个参数,分别是"@name"和"@id",最终返回受影响的行数。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)