How to run multiple SQL commands in a single SQL connection?

前端 未结 9 999
野的像风
野的像风 2020-11-27 15:03

I am creating a project in which I need to run 2-3 SQL commands in a single SQL connection. Here is the code I have written:

SqlConnection con = new SqlConn         


        
9条回答
  •  抹茶落季
    2020-11-27 15:54

    Multiple Non-query example if anyone is interested.

    using (OdbcConnection DbConnection = new OdbcConnection("ConnectionString"))
    {
      DbConnection.Open();
      using (OdbcCommand DbCommand = DbConnection.CreateCommand())
      {
        DbCommand.CommandText = "INSERT...";
        DbCommand.Parameters.Add("@Name", OdbcType.Text, 20).Value = "name";
        DbCommand.ExecuteNonQuery();
    
        DbCommand.Parameters.Clear();
        DbCommand.Parameters.Add("@Name", OdbcType.Text, 20).Value = "name2";
        DbCommand.ExecuteNonQuery();
      }
    }
    

提交回复
热议问题