【问题标题】:How to clear a few tables content in same time如何同时清除几个表格内容
【发布时间】:2016-01-13 16:51:11
【问题描述】:

我编写此代码是为了从 Mysql 的数据库中删除一个表,并且它工作正常。 如何使用最少代码同时删除几个表? 谢谢

private void button3_Click(object sender, EventArgs e)
{
    string constring = "datasource=localhost;port=3306;username=root;password=abcd";
    using (MySqlConnection cnn = new MySqlConnection(constring))
    using (MySqlCommand cmd = new MySqlCommand("TRUNCATE TABLE myproject.words", cnn))
    {
        cnn.Open();
        cmd.ExecuteNonQuery();
    }
}

【问题讨论】:

标签: c# mysql


【解决方案1】:

只需链接命令

using (MySqlCommand cmd = 
       new MySqlCommand("TRUNCATE TABLE myproject.words; TRUNCATE TABLE myproject.other;"  
       , cnn))

【讨论】:

  • 太棒了。非常感谢。
  • 如果您使用它作为答案,那么您可以单击检查
猜你喜欢
  • 1970-01-01
  • 2018-07-08
  • 2016-01-15
  • 1970-01-01
  • 2019-05-09
  • 1970-01-01
  • 1970-01-01
  • 2020-09-30
相关资源
最近更新 更多